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
- 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.deploycreates 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.
How it works
Serving with Foundation Model APIs
| Option | What it gives you | Pick it when |
|---|---|---|
| Pay per token | Shared, ready endpoints billed per token | Prototypes, variable or low traffic |
| Provisioned throughput | Dedicated capacity with performance guarantees | Production load, fine tuned models, compliance needs such as HIPAA |
| External models | A Databricks endpoint that proxies a provider such as OpenAI | The 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.
| Method | Runs as | How you set it up |
|---|---|---|
| Automatic authentication passthrough | A system service principal with short lived credentials | List resources such as DatabricksServingEndpoint, DatabricksVectorSearchIndex, DatabricksFunction, DatabricksGenieSpace in resources when logging |
| On behalf of user (Public Preview) | The end user who sent the request | Log with an auth policy that declares the user API scopes |
| Manual authentication | A service principal or token you supply | Pass 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.
User facing interfaces
| Users | Interface |
|---|---|
| Internal users who need a branded chat page | A Databricks App built from a chat template |
| Teams that live in Slack or Microsoft Teams | A bot in that tool that calls the agent's serving endpoint through its REST API |
| Analysts asking questions about tables | An AI/BI Genie space |
| Subject matter experts testing quality | The 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.deploycreates 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; setfailOnError => falsefor large jobs.
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.