Courses · The Ambush Method

Pick your exam.

Every guide follows the same method: short daily sessions, the traps each topic sets, and exam-style questions with an explanation for every option.

  • 100% free · no paywalls, subscriptions or ads
  • 30–60 min a day
  • Exam-style questions
  • Taught in English

Databricks Model Serving vs ai_query: Batch vs Real-Time Inference

Databricks Model Serving vs ai_query featured image: Is anyone waiting? A practice card picks one ai_query over a Delta table instead of scaling a serving endpoint

Picture two requests landing on the same team in the same week. One is a support assistant: a person types a question and waits for the answer. The other is a backfill: millions of old tickets in a Delta table that need a summary and a category by Monday. Both use the same LLM, and that’s exactly why people reach for the same tool for both. On the Generative AI Engineer Associate exam, that reflex is the trap. Databricks Model Serving is the right home for the first job, and a single ai_query query is the right home for the second. This post is about telling them apart from the wording of a scenario, before any product name enters your head.

If you’re new here, my Databricks Generative AI Engineer Associate study guide has the full exam map. This post zooms into two lines of it that sit in the deployment section, and they’re two of the most reliably tested details in that section.

What the exam actually asks

The official exam guide puts both objectives in Section 4, Assembling and Deploying Applications, which carries 22% of the exam. Word for word, they are: “Identify how to serve an LLM application that leverages Foundation Model APIs” and “Identify batch inference workloads and apply ai_query() appropriately.”

Look at the verbs: “identify.” Neither objective asks you to remember a menu path. Both ask you to read a situation and recognize its shape, then pick the instrument that fits.

Databricks Model Serving in one picture

Model Serving is the infrastructure. It hosts models and exposes each one as a REST endpoint that an application can call. The Model Serving docs describe it as a unified interface to deploy, govern and query models for both real-time and batch inference, running on serverless compute that scales up and down with demand.

Three kinds of things can sit behind an endpoint:

  • Custom models: anything you logged with MLflow and registered, including agents. Your RAG chain from the RAG post ends up here.
  • Databricks-hosted foundation models: open and partner models that Databricks already runs for you, reached through Foundation Model APIs.
  • External models: third-party providers such as OpenAI or Anthropic, routed through the same interface so they’re governed in one place.

The way I picture it: Model Serving is the kitchen, and Foundation Model APIs is a drive-through window bolted to the front of it. The window is a curated menu of models that are already cooking. You order by name, you never touch the stove.

The trap: Foundation Model APIs vs Model Serving

This is the first ambush on this objective. A scenario asks how to serve an LLM app that uses Foundation Model APIs, and one option treats Foundation Model APIs and Model Serving as two rival products you choose between. They aren’t rivals. One is the interface and the other is the infrastructure it runs on. The giveaway is right there in the code: when you call a hosted model with the OpenAI client, the base URL ends in /serving-endpoints.

from openai import OpenAI
import os

# The standard OpenAI client, pointed at your workspace's serving endpoints.
client = OpenAI(
    api_key=os.environ["DATABRICKS_TOKEN"],
    base_url=f"{os.environ['DATABRICKS_HOST']}/serving-endpoints",
)

reply = client.chat.completions.create(
    model="databricks-meta-llama-3-3-70b-instruct",  # a pay-per-token endpoint name
    messages=[{"role": "user", "content": "Classify this ticket: 'I was charged twice.'"}],
    max_tokens=100,
)
print(reply.choices[0].message.content)

That’s the whole first call. No GPU to provision, no weights to download. The model string is a serving endpoint name, and the response gives you three things worth reading every time: the answer, the token usage (your bill), and the time it took (your latency).

The practical split the exam leans on: when the thing you call is a prebuilt foundation model, you reach it through Foundation Model APIs. When the thing you serve is a model your team built and registered, you deploy it as its own Model Serving endpoint. Same kitchen, different jobs.

Pay-per-token vs provisioned throughput

Foundation Model APIs has more than one way to bill you, and the exam tests whether you can match the mode to the traffic. Here’s how the Foundation Model APIs page lays them out today:

  • Pay-per-token: preconfigured endpoints, nothing to reserve, billed by tokens in and out. The easiest way to start, and the right fit for prototyping, evaluation runs, and light or bursty traffic. It’s best effort, so it doesn’t promise sustained throughput.
  • Provisioned throughput: you reserve serving capacity for a workload. You get performance guarantees, and it’s the mode for fine-tuned or custom models and stricter security or compliance needs. Databricks recommends it for production workloads.
  • AI Functions optimized models: the mode recommended for batch inference, reached from SQL through AI Functions such as ai_query.

The rule I keep in my head: pay-per-token for trying things and for bursts, provisioned throughput for steady production load that needs guarantees, AI Functions for piles of rows. Match the mode to the shape of the traffic, not to how serious the project feels.

What changed in the docs recently

When I checked in early November 2026, the docs had moved a little past the exam’s wording, so don’t let a current screenshot throw you. Three things stood out. Pay-per-token now has an opt-in priority mode (priority pay-per-token) for latency-sensitive traffic, billed at a higher rate per token. Provisioned throughput now comes in two options, on-demand with no term commitment and reserved for a fixed term. And each hosted model now also has a system-provided model service name in Unity AI Gateway, like system.ai.meta-llama-3-3-70b-instruct, next to its classic databricks- endpoint name. The supported models list shows both, and you can query with either; custom model services add routing and fallbacks on top. For the exam, the three modes above are still the mental model to bring.

The real question: is anyone waiting?

Now the second objective, and the one with the more expensive mistake. The reflex goes like this: an endpoint is simply how you run a model, so scoring eleven million rows means calling the endpoint eleven million times. Experienced engineers add a worker pool, backoff and more provisioned concurrency. That’s a professional answer to the wrong question.

A drive-through window serves one car at a time, and it’s judged by one number: how long each car waits. Bring it a banquet of ten thousand meals needed by tomorrow morning and widening the window doesn’t help. You still asked for ten thousand separate transactions, each one paying the full cost of being a transaction. What you actually have is one big order that should be cooked in one run.

So before you name any tool, ask three questions:

  • Is anyone waiting on this particular answer? A person, a page, a synchronous call from another service: that’s real time. A report, an enrichment job, a backfill, a nightly refresh: nobody is waiting.
  • How does the work arrive? One request at a time, unpredictably, means serving. Rows that already exist in a table means batch.
  • What does “done” mean? Milliseconds for one answer, or the whole set finished before a deadline? Those are opposite kinds of success, and they’re optimized by opposite means.

Words about time per request (latency, response time, queries per second, uptime) are telling you somebody is standing at the window. Words about work completed (large dataset, throughput, nightly schedule, refresh, job finishing) are telling you there’s a pile. When both show up in one paragraph, the one attached to a person usually wins, because a human waiting is a hard constraint.

Why scaling the endpoint doesn’t fix a batch job

This is the trap I’d circle twice, because every wrong option here is written in the language of competence. Raise the concurrency. Stand up a provisioned throughput endpoint for the nightly window. Split the job into a hundred smaller batches. They all sound like responsible capacity planning.

Here’s why they fail. Endpoints have ceilings per endpoint and per workspace, documented on the Model Serving limits page. Hosted foundation models also enforce rate limits on input tokens per minute, output tokens per minute and queries per hour, and the Foundation Model APIs limits page is explicit that the most restrictive one applies at any given time. Cross one and you get an HTTP 429, too many requests. A retry loop that answers a 429 by trying again shortly has misunderstood the message. And even past all of that, you’re still paying per-request overhead once per row.

Capacity fixes a size problem. It can’t touch a shape problem. When a workload is slow, ask whether it’s the wrong shape before you ask whether it’s the wrong size.

The trap also runs the other way, and the exam knows it. Send a waiting user’s question to a scheduled batch job and the answer isn’t a bit slower. It arrives on the next run, which might be tomorrow.

ai_query: bring the model to the data

Batch inference on Databricks wears the most ordinary disguise possible: a SQL function. ai_query is a scalar expression in a SELECT list, sitting next to a column, over a governed table. No client, no loop, no worker pool. The model goes to the data, not the other way around.

SELECT
  ticket_id,
  ai_query(
    endpoint    => 'databricks-meta-llama-3-3-70b-instruct',  -- an endpoint name, not a model path
    request     => 'Classify this ticket as billing, technical or other: ' || body,
    failOnError => false                                      -- bad rows return an error, not a dead job
  ) AS result
FROM main.support.tickets;

If you’re preparing for the exam and want this kind of shape reading drilled every day, that’s exactly what my free course is built around: a short lesson, the trap it hides, and practice that makes you name the shape first. More on that at the end.

The first argument is an endpoint, not a model

Read the first argument again, because it’s the detail I’d bet on seeing. It’s the name of a serving endpoint, as a string literal. Not the name of a model you logged with MLflow, and not the three-part Unity Catalog path of a registered model version. The docs say it plainly: the endpoint must be a foundation model, external model or custom model endpoint in the same workspace, and the definer needs CAN QUERY on it. If you fine-tuned a model, you deploy it behind an endpoint first and then name that endpoint. The newer docs also accept a system-provided model service name such as system.ai.meta-llama-3-3-70b-instruct, which is still something that is already serving, never a registered model sitting in the catalog.

So yes, there is still an endpoint involved in batch. What changes is who does the calling. You place one order, and AI Functions work through it in a single run, parallelizing and retrying on their own, while your live endpoint stays free for the person waiting at the window.

The settings that matter on a real run

  • failOnError: defaults to true, which means one bad row from the endpoint fails the whole statement. Set it to false and the function returns a struct with the response and an error message for each row, so a few failures stay a few rows you inspect and retry.
  • responseFormat: for chat foundation models, this is how you ask for structured output (a JSON schema or a DDL-style struct) so results land as something you can query instead of free text. returnType is the argument for custom model endpoints.
  • modelParameters: constant settings such as max_tokens and temperature. Worth knowing that ai_query defaults temperature to 0.0.

Three batch rules straight from the docs

The AI Functions page lists best practices for production, and each one maps to a tempting wrong answer:

  • Submit the full dataset in a single query. AI Functions manage parallelization, retries and scaling themselves. Splitting the work into small batches by hand is the instinct that serves you well elsewhere and hurts you here.
  • Use Databricks-hosted foundation models, not provisioned throughput. The docs recommend the databricks- prefixed, provisionless endpoints for batch. So “provision a throughput endpoint for the nightly window” isn’t a defensible trade-off. It’s the direction the documentation steers you away from.
  • Mind the compute. The current docs say AI Functions are not available on Classic SQL warehouses. Older material, including my own notes, put it more strictly as serverless only, so treat a scenario that names a Classic warehouse as a red flag and serverless as the safe answer.

In practice, the real version of that nightly backfill is a scheduled query, not a service. You write the ai_query statement over the source table, write results back to Delta, and schedule it with Databricks workflows or a Lakeflow pipeline. The batch inference pipelines page shows both, plus a Structured Streaming option for data that keeps arriving. The live assistant keeps its endpoint, the pile goes through a query, and the two workloads stop competing.

A quick way to sort any scenario

When you hit a serving question, run this in order:

  • Who is waiting? Nobody means batch with ai_query. A person or a synchronous caller means a serving endpoint.
  • If it’s an endpoint, what’s being served? A hosted foundation model goes through Foundation Model APIs. Your own registered model or agent gets its own Model Serving endpoint.
  • If it’s a foundation model, what’s the traffic? Prototype or bursts means pay-per-token. Sustained production load with guarantees, or a fine-tuned model, means provisioned throughput.
  • If it’s batch, check the details: endpoint name as the first argument, one query over the whole table, failOnError set to false, a hosted databricks- endpoint, and no Classic warehouse.

One last reminder: if a served RAG chain suddenly can’t read its index, that’s an access question about the endpoint’s identity, not a capacity one. I covered the index side in Databricks Vector Search explained, and if you’re deciding whether to build that agent at all, see Agent Bricks: when to rent and when to build.

FAQ

Is ai_query part of Databricks Model Serving?

They work together. ai_query is a SQL function that invokes an existing Model Serving endpoint. Model Serving hosts the model; ai_query is the batch-friendly way to apply it across a table from SQL.

What is the first argument to ai_query?

The name of a serving endpoint in the same workspace, as a string, and you need CAN QUERY on it. Never the Unity Catalog path of a registered model. Newer docs also accept a system-provided model service name such as system.ai.<model>.

When should I use pay-per-token instead of provisioned throughput?

Pay-per-token for prototyping, evaluation and light or bursty traffic. Provisioned throughput for sustained production workloads that need performance guarantees, and for fine-tuned or custom models.

Can I use provisioned throughput for batch inference with ai_query?

You can point ai_query at one, but Databricks recommends the hosted, provisionless databricks- endpoints for batch. On the exam, provisioning throughput for a nightly job is the tempting wrong answer.

Should I split a large batch job into smaller chunks?

No. Submit the full dataset in a single query and let AI Functions handle parallelization, retries and scaling.

Keep studying, 30-60 minutes at a time

None of this needs a marathon. Take one evening to read the scenario shapes, one to make a first Foundation Model APIs call, and one to run ai_query over a small table with failOnError set to false. That’s the ambush idea: learn where the traps sit, in short daily sessions, instead of memorizing dumps.

If you want that path laid out for you, my free Databricks Generative AI Engineer Associate course walks through every exam section the same way, trap by trap. And if you’re still planning your approach, read how to pass without dumps first. See you in the next one.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *