passdrill

Building with LLM APIs

12 cards · AI & LLM Engineering · answer each one, then read the explanation. Your score tallies below.

0 / 12 answered · 0 correct
AI & LLM Engineering · Building with LLM APIs · Card 001/012 easy

When an LLM API's "function calling" (tool use) feature returns a function call in its response, what actually happens next in a typical integration?

  1. The API executes the function directly on the vendor's infrastructure and returns only the final answer text, with no involvement from the calling application
  2. The response contains a structured description of the function name and the arguments the model wants to pass; the calling application must run the actual function itself and send the result back in a follow-up request
  3. The model runs the function inside its own weights using an internal code interpreter, producing the function's return value without any external execution step
  4. The request fails with an error unless the function has already been executed and its output included as part of the original prompt
AI & LLM Engineering · Building with LLM APIs · Card 002/012 easy

Many LLM provider APIs offer a "streaming" mode for text generation, typically implemented over Server-Sent Events (SSE). What does enabling streaming change about how a client receives the model's output?

  1. The client receives the complete response in a single payload, but compressed with gzip to reduce total bandwidth compared to a non-streaming request
  2. The model generates its answer in a single internal pass regardless of the setting; streaming only changes how the response is logged on the provider's servers, not how the client receives it
  3. The client receives the response as a sequence of incremental chunks over an open connection as tokens are generated, rather than waiting for generation to finish before anything is returned
  4. The client must poll a separate status endpoint at fixed intervals to check whether generation has completed, since no data is returned until the full response is ready
AI & LLM Engineering · Building with LLM APIs · Card 003/012 easy

An LLM API's "context window" limit of, say, 200,000 tokens applies to what, specifically, during a single API call?

  1. The combined total of the input tokens sent in the request (system prompt, conversation history, and any injected documents) plus the output tokens the model generates in response
  2. Only the tokens in the user's most recent message, since earlier turns in the conversation are automatically summarized and don't count against the limit
  3. Only the tokens the model generates in its response, since input tokens are processed by a separate, effectively unlimited ingestion pipeline
  4. The number of separate API requests a client can make per minute before being rate-limited
AI & LLM Engineering · Building with LLM APIs · Card 004/012 medium

A client application calling an LLM API in a tight loop starts receiving HTTP 429 responses. What is the generally recommended way to handle this, per common LLM provider API documentation?

  1. Immediately retry the exact same request as fast as possible in a loop, since 429 responses are transient and will resolve within milliseconds if retried aggressively
  2. Switch to a different, unrelated API endpoint entirely, since a 429 on one endpoint indicates that the provider's entire platform is unavailable
  3. Reduce the `max_tokens` parameter on the failing request, since 429 responses indicate the requested output would be too long to generate
  4. Back off and retry after a delay that increases with each subsequent failure (exponential backoff), typically with some added random jitter, rather than retrying immediately or at a fixed short interval
AI & LLM Engineering · Building with LLM APIs · Card 005/012 easy

How does a typical LLM provider's embeddings endpoint differ from its text-completion/chat-generation endpoint?

  1. The embeddings endpoint is simply a faster version of the generation endpoint that returns shorter natural-language answers to save on output tokens
  2. The embeddings endpoint takes text as input and returns a fixed-length numeric vector representing that text's meaning, rather than generating new natural-language text
  3. The embeddings endpoint only works on images, while the generation endpoint only works on text, so the two cannot be used on the same type of content
  4. The embeddings endpoint requires fine-tuning a custom model first, while the generation endpoint works with any base model out of the box
AI & LLM Engineering · Building with LLM APIs · Card 006/012 easy

What does the `stop` (or "stop sequences") parameter available in most LLM generation APIs do?

  1. It tells the API to stop generating further tokens as soon as any one of a specified list of strings appears in the output, and to exclude that string from the returned text
  2. It sets a maximum wall-clock time limit in seconds after which the API forcibly terminates the connection regardless of how much text has been generated
  3. It specifies a list of words the model is never permitted to generate anywhere in its response, causing an error if any of them would otherwise be produced
  4. It pauses generation partway through and waits for the client to send an approval signal before continuing to generate the remainder of the response
AI & LLM Engineering · Building with LLM APIs · Card 007/012 hard

A developer is using Anthropic's Messages API with two tools defined, `get_weather` and `send_email`, and wants to guarantee that Claude calls `get_weather` specifically on this turn rather than answering in plain text or calling `send_email`. According to Anthropic's tool-use documentation, how is this accomplished?

  1. By removing `send_email` from the `tools` array entirely for this request, since `tool_choice` can only force "any" tool use, not a specific named tool
  2. By setting `tool_choice` to `{"type": "any"}`, which restricts the model to only the first tool listed in the `tools` array
  3. By setting `tool_choice` to `{"type": "tool", "name": "get_weather"}`, which forces the model to call that specific named tool rather than deciding on its own or calling a different one
  4. By adding the instruction "you must call get_weather" only to the system prompt, since `tool_choice` itself has no mechanism for naming a specific tool
AI & LLM Engineering · Building with LLM APIs · Card 008/012 medium

A developer building a multi-turn conversational app compares OpenAI's Chat Completions API to its Responses API. According to OpenAI's documentation, what is a key difference in how each manages conversation state across turns?

  1. Chat Completions automatically stores and threads every conversation server-side with no client involvement, while the Responses API requires the client to resend the entire message history on every call
  2. Both APIs require the exact same manual approach: the client must always reconstruct and resend the full list of prior user and assistant messages with every request, with no built-in alternative in either API
  3. The Responses API has no way to maintain multi-turn context at all, and is only suitable for single-turn, stateless requests unrelated to any previous exchange
  4. With Chat Completions, the client must append prior turns into the message array and resend the full history each call, while the Responses API can instead reference a prior turn via a `previous_response_id` parameter so the server carries the context forward
AI & LLM Engineering · Building with LLM APIs · Card 009/012 medium

An LLM-powered agent has a tool that charges a customer's payment method, and the agent's HTTP call to your backend times out after the charge has actually already been processed. The agent's retry logic then calls the same tool again with the same arguments. What design choice prevents this from resulting in a duplicate charge?

  1. Having the tool accept a unique idempotency key per logical operation, so the backend can recognize a retried call with the same key and return the original result instead of processing the charge a second time
  2. Increasing the model's `max_tokens` limit, so the agent has enough space to reason more carefully about whether a retry is safe before calling the tool again
  3. Lowering the model's `temperature` to 0, so the agent always generates the exact same tool call arguments and therefore never issues an unintended duplicate request
  4. Disabling the agent's ability to call tools more than once per conversation, so any repeated call is rejected outright regardless of what happened to the first one
AI & LLM Engineering · Building with LLM APIs · Card 010/012 easy

Some LLM APIs support returning `logprobs` (log probabilities) alongside generated text. What do these values represent, and what are they typically used for?

  1. They report how many milliseconds the API took to generate each token, and are used purely for latency monitoring and performance debugging
  2. They report, for each generated token, the log probability the model assigned to it (and often to alternative candidate tokens), and are typically used to gauge the model's confidence or build classifiers from token likelihoods
  3. They report the total dollar cost billed for each individual token, broken out on a per-token basis for detailed cost accounting
  4. They report which of several fine-tuned model versions actually generated each token, for use in auditing which checkpoint produced a given response
AI & LLM Engineering · Building with LLM APIs · Card 011/012 medium

An LLM generation API exposes both a `top_p` (nucleus sampling) parameter and, in some APIs, a `top_k` parameter, in addition to `temperature`. How does nucleus sampling with `top_p` differ from `top_k` sampling in how it restricts the model's next-token choices?

  1. `top_p` and `top_k` are two names for the exact same mechanism, differing only in whether the cutoff value is expressed as a percentage or as a raw integer
  2. `top_k` restricts choices based on cumulative probability mass, so its cutoff point moves depending on how confident the model is at each step, while `top_p` always keeps exactly the same fixed number of candidates
  3. `top_p` restricts sampling to the smallest set of most-probable tokens whose cumulative probability reaches the threshold `p`, so the number of candidates varies step to step, while `top_k` always keeps a fixed number of the highest-probability tokens regardless of how the probability mass is distributed
  4. Both parameters only take effect when `temperature` is set to exactly 0, and have no effect on generation at any other temperature value
AI & LLM Engineering · Building with LLM APIs · Card 012/012 hard

A team needs to run sentiment classification over 40,000 archived support tickets and is not latency-sensitive, but wants to minimize per-request cost. According to OpenAI's Batch API documentation, what tradeoff does using the Batch API (instead of the standard synchronous chat completions endpoint) involve?

  1. The Batch API charges the same per-token price as the synchronous API but guarantees results within 60 seconds regardless of batch size
  2. The Batch API is free of charge for any volume of requests, but results are only available after a mandatory 7-day waiting period
  3. The Batch API only accepts a single request per batch, so the team would still need to submit 40,000 separate batch jobs to process all the tickets
  4. The Batch API offers roughly a 50% cost discount compared to the synchronous API, but processes the submitted batch of requests asynchronously with results typically available within 24 hours rather than immediately, and draws from a separate rate-limit pool