Assembling and Deploying Applications · Topic 3 of 4

Serving, Access Control, Batch Inference and Interfaces

Databricks GenAI Engineer: serving on Foundation Model APIs, endpoint access to resources, batch inference with ai_query and chat UIs on Databricks Apps.

  • 5 min
In a nutshell
  • Pay per token is for getting started; provisioned throughput is for production guarantees and fine tuned models.
  • External models put providers such as OpenAI behind a governed Databricks endpoint.
  • agents.deploy creates the endpoint plus tracing, inference tables and the Review App.

What it is

Once a chain or agent is registered in Unity Catalog, Mosaic AI Model Serving runs it behind a REST endpoint. The LLM inside it is usually reached through Foundation Model APIs, and the endpoint needs credentials for every index, function or model it calls.

Not every workload is a live chat. Scoring a whole table belongs to ai_query() in SQL, and people reach the agent through an interface such as a Databricks App or a chat tool they already use.

Registered agentModel Serving endpointcredentials for resourcesFoundation Model APILLMChat UI or SQL batch

How it works

Serving with Foundation Model APIs

OptionWhat it gives youPick it when
Pay per tokenShared, ready endpoints billed per tokenPrototypes, variable or low traffic
Provisioned throughputDedicated capacity with performance guaranteesProduction load, fine tuned models, compliance needs such as HIPAA
External modelsA Databricks endpoint that proxies a provider such as OpenAIThe requirement names a model hosted outside Databricks

Most Foundation Model API endpoints are OpenAI compatible, so the OpenAI client works against them. Your chain calls the LLM endpoint by name, and the agent itself is deployed to its own serving endpoint.

from databricks import agents
deployment = agents.deploy("main.docs.rag_chain", 3)
print(deployment.query_endpoint)

agents.deploy(model_name, version) creates the serving endpoint and also turns on MLflow tracing, inference tables, the Review App and production monitoring for the agent.

Controlling access to resources

The endpoint runs your code, so it needs an identity for each resource it touches.

MethodRuns asHow you set it up
Automatic authentication passthroughA system service principal with short lived credentialsList resources such as DatabricksServingEndpoint, DatabricksVectorSearchIndex, DatabricksFunction, DatabricksGenieSpace in resources when logging
On behalf of user (Public Preview)The end user who sent the requestLog with an auth policy that declares the user API scopes
Manual authenticationA service principal or token you supplyPass secrets as environment variables, for example {{secrets/scope/key}}

With automatic passthrough, Databricks checks that the person deploying has access, for example Can Query on a serving endpoint, EXECUTE on a Unity Catalog function or SELECT on a table. Choose on behalf of user when each user must see only the data their own permissions allow. Choose manual authentication for resources outside Databricks, such as an external API key kept in a secret scope.

Who may call the endpoint itself is a separate setting: endpoint permissions are CAN VIEW, CAN QUERY and CAN MANAGE.

Batch inference with ai_query

ai_query() calls a model from SQL for every row, which suits scheduled jobs over tables: classifying tickets, summarizing reviews or extracting fields.

SELECT ticket_id,
  ai_query('support_batch_llm',
           CONCAT('Classify this ticket as billing, bug or other: ', body),
           failOnError => false) AS category
FROM main.support.tickets;

Databricks scales the batch for you, so submit the whole table in one query rather than splitting it. For production scale batches, use a batch optimized Databricks hosted model or a provisioned throughput endpoint; pay per token endpoints are meant for real time use. With failOnError => false the result is a struct holding the response and an error message, so failed rows are reported instead of stopping the job.

Delta tablethousands of rowsai_queryin SQL or a jobResults table

User facing interfaces

UsersInterface
Internal users who need a branded chat pageA Databricks App built from a chat template
Teams that live in Slack or Microsoft TeamsA bot in that tool that calls the agent's serving endpoint through its REST API
Analysts asking questions about tablesAn AI/BI Genie space
Subject matter experts testing qualityThe Review App

A Databricks App runs with its own service principal by default, or with user authorization when each user's permissions must apply. A Slack or Teams bot authenticates to the endpoint with a service principal.

How the exam asks about this

  • "Nightly, summarize two million product reviews stored in a Delta table." Use ai_query() in a scheduled SQL job, not a real time endpoint loop.
  • "The deployed agent returns permission errors when it calls the Vector Search index." Declare the index in resources so automatic authentication passthrough covers it.
  • "A production chatbot needs guaranteed throughput on a fine tuned Llama model." Serve it with provisioned throughput.

What to remember for the exam

  • Pay per token is for getting started; provisioned throughput is for production guarantees and fine tuned models.
  • External models put providers such as OpenAI behind a governed Databricks endpoint.
  • agents.deploy creates the endpoint plus tracing, inference tables and the Review App.
  • Automatic passthrough needs the resources declared when the model is logged.
  • On behalf of user authentication applies each caller's own permissions.
  • ai_query() is the batch answer for rows in a table; set failOnError => false for large jobs.
Watch out

Do not put an API key in agent code or in a notebook variable. Store it in a secret scope and reference it as an environment variable on the endpoint.

Common mistakes

Calling a serving endpoint in a Python loop for a table. A loop is slow and fragile. ai_query() processes the table in parallel and handles scaling.

Using the Review App as the production interface. The Review App collects expert feedback during development. End users get a Databricks App or a bot in their chat tool.

Confusing endpoint permissions with resource access. CAN QUERY lets a user call the endpoint. What the agent can read is decided by its own credentials, through passthrough, on behalf of user or manual secrets.

Check yourself

  • Which serving option fits a fine tuned model that needs guaranteed throughput?

    Provisioned throughput, because it gives dedicated capacity with performance guarantees and supports fine tuned models.

  • When should an agent use on behalf of user authentication?

    When each request must be limited to the data the calling user is allowed to see, since the agent then acts with that user's permissions.

  • Why is ai_query() the right tool for scoring a large table?

    It runs the model over every row from SQL, scales the batch automatically and fits scheduled jobs better than a real time endpoint loop.

Topic 3 of 4 in Assembling and Deploying Applications

Test yourself on Assembling and Deploying Applications

The full Databricks Generative AI Engineer Associate question bank has 600 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Databricks. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.