AI Foundations · 20% of the exam

AI Engineering Basics: free practice questions

5 sample questions from our 261-question bank for this domain — answers and explanations included. These are the same scenario-based style as the real DataCertPrep exam.

1. A team is streaming responses from the Anthropic Messages API using server-sent events. They need to detect the moment the model finishes generating so they can trigger a downstream process. Which event type in the Anthropic streaming protocol signals that the message is fully complete?

  • A. `content_block_stop`
  • B. `message_delta` with `stop_reason: "end_turn"`
  • C. `message_stop`✓ Correct
  • D. `stream_end`
Explanation

`message_stop` is the final event emitted by the Anthropic streaming API and definitively signals that the entire message, including all content blocks, has been fully generated and the stream is closed. **Why the distractors are wrong:** - (A) `content_block_stop` signals the end of a single content block (e.g., a text segment), not the end of the full message. Multiple content blocks can exist in one message. - (B) `message_delta` with `stop_reason: "end_turn"` carries metadata about why generation stopped, but it precedes `message_stop`; it is not itself the terminal signal. - (D) `stream_end` is not a real Anthropic SSE event type; this is a distractor.

2. A developer is profiling their production application and finds that TPM (tokens per minute) limits are being hit even though RPM (requests per minute) limits are not. Which TWO strategies would most effectively reduce TPM consumption without switching to a different model or reducing response quality?

  • A. Implement prompt compression techniques — such as removing redundant context, summarizing conversation history, or using retrieval-augmented generation to inject only relevant chunks — to reduce input token counts.✓ Correct
  • B. Increase `max_tokens` per request to allow the model to finish responses in fewer requests.
  • C. Use the Batch API for non-latency-sensitive workloads to shift token consumption to a separate rate-limit pool.
  • D. Set `temperature: 1.5` to encourage shorter, more creative responses.
  • E. Cache responses client-side for identical or near-identical prompts so repeated queries do not consume additional API tokens.✓ Correct
  • F. Reduce the `top_p` parameter to 0.1 to force the model to use fewer tokens per response.
Explanation

Prompt compression (shorter inputs via summarization, history pruning, or RAG) directly reduces input tokens per request. Client-side caching of responses means identical prompts never hit the API at all, eliminating their token consumption entirely. Both strategies target the root cause of high TPM. Option B is wrong — increasing `max_tokens` allows the model to generate *more* output tokens, worsening TPM. Option C is a valid cost and throughput strategy, but the Batch API has its own separate limits; it doesn't reduce TPM on the synchronous pool. Option D is wrong — `temperature: 1.5` affects randomness, not response length or token count. Option F is wrong — `top_p` affects sampling distribution and does not meaningfully reduce the number of tokens generated.

3. A developer receives an HTTP 401 error when calling the Anthropic Messages API. After verifying the API key is correct, they discover the key is being passed in the `Authorization: Bearer` header. What is the actual cause of the error?

  • A. Anthropic requires the API key to be passed as `x-api-key` header, not `Authorization: Bearer`✓ Correct
  • B. The `Content-Type` header is missing; Anthropic requires `application/json` before authenticating
  • C. The API key must be Base64-encoded before being placed in any HTTP header
  • D. Anthropic uses OAuth 2.0 token exchange, so a raw API key cannot be used directly
Explanation

Anthropic's API uses a **custom header `x-api-key: <YOUR_API_KEY>`** for authentication, unlike OpenAI which uses the standard `Authorization: Bearer` header. Sending the key in `Authorization: Bearer` is a common mistake made by developers familiar with OpenAI, and it results in a 401 Unauthorized error. Option B is incorrect because while `Content-Type: application/json` is required for POST requests, its absence typically results in a 400 error about the request body, not a 401 authentication error. Option C is incorrect because API keys are passed as plaintext strings in headers; Base64 encoding is used in HTTP Basic Auth, not API key auth. Option D is incorrect because Anthropic uses simple API key authentication, not OAuth 2.0 token flows.

4. A developer is building a document summarization service. Each request sends a 10,000-token document with a 500-token system prompt and expects a 300-token summary in return. The model costs $3.00 per 1M input tokens and $15.00 per 1M output tokens. They want to enable OpenAI prompt caching for the system prompt. What is the MOST accurate statement about the expected cost impact?

  • A. Prompt caching will have minimal cost impact because the cached system prompt (500 tokens) is small relative to the 10,000-token document, which cannot be cached per-request.✓ Correct
  • B. Prompt caching will cut costs by 50% because the entire input (system prompt + document) is cached after the first request.
  • C. Prompt caching will reduce the cost of the system prompt portion by 50%, saving $0.75 per 1M requests.
  • D. Prompt caching eliminates all input token charges on cache hits, so the savings will be 100% of the input cost.
Explanation

OpenAI's prompt caching applies to the prefix of the prompt that is reused across requests. Here, only the 500-token system prompt is static and cacheable; the 10,000-token document changes per request and cannot be cached. Since the document dominates input volume (~95% of input tokens), caching only the system prompt produces negligible overall savings. Option B is incorrect — the full input is not cached; only the static prefix is. Option C correctly identifies that caching reduces the system prompt cost (by ~50%) but the phrasing '$0.75 per 1M requests' conflates the math; more importantly, this option implies a meaningful saving, which is misleading given the tiny cached fraction. Option D is incorrect — OpenAI's prompt caching offers a discount (approximately 50%) on cached tokens, not a 100% elimination of charges.

5. An engineer is designing a RAG application where each API call includes a 4,000-token retrieved context block followed by a short 200-token user question. They want to use OpenAI's prompt caching to reduce costs. Which design decision is MOST critical for ensuring cache hits?

  • A. Ensure the cached prefix (the large context block) appears at the beginning of the prompt and remains byte-for-byte identical across requests; only the user question at the end should vary.✓ Correct
  • B. Enable caching by passing `cache: true` in the API request body so OpenAI knows to store the prompt.
  • C. Keep the total prompt under 8,192 tokens because OpenAI's prompt cache does not support prompts longer than that threshold.
  • D. Rotate the context block on every third request to prevent cache staleness and avoid stale-data penalties.
Explanation

Option A is correct: OpenAI's prompt caching works on exact prefix matches — the cached portion must be a verbatim prefix of the prompt. Placing the large, stable context at the start and appending only the variable user query at the end maximizes cache reuse. Option B is wrong: OpenAI's prompt caching is automatic for eligible prompts (≥1,024 tokens) — there is no `cache: true` parameter to set. Option C is wrong: prompt caching supports prompts well beyond 8,192 tokens; the minimum threshold for caching eligibility is 1,024 tokens. Option D is wrong: rotating the context defeats the purpose of caching by ensuring cache misses, and there is no 'stale-data penalty' mechanism in OpenAI's caching.

256 more questions in this domain

Practice the full bank with instant grading, flashcards, and a timed mock exam.

Start practicing free