Claude API / OpenAI API Basics interview questions

29 questions from the Claude API / OpenAI API Basics course, each with the correct answer and an explanation. Try to answer before you open the answer.

How LLM APIs Work

1. What does "stateless" mean for an LLM API?

  1. It only works offline
  2. It stores your conversation forever for free
  3. It remembers nothing between calls, so you resend the conversation
  4. It has no billing
Show answer

Answer: It remembers nothing between calls, so you resend the conversation

Each request must carry all the context the model needs.

Lesson: What an LLM API Is

2. Where should an API key live in a web application?

  1. On your backend, in an environment variable or secrets manager
  2. In the browser JavaScript
  3. In a public GitHub repository
  4. In the page HTML comments
Show answer

Answer: On your backend, in an environment variable or secrets manager

Anything shipped to a client can be extracted; keep keys server-side.

Lesson: API Keys, Environment Variables and Safe Setup

3. What do SDKs add on top of raw HTTP?

  1. No need for a key
  2. A different model
  3. Free tokens
  4. Typed objects, retries, timeouts and streaming helpers
Show answer

Answer: Typed objects, retries, timeouts and streaming helpers

SDKs wrap the same HTTP API with convenience and reliability features.

Lesson: A Raw HTTP Call: What the SDK Does for You

4. Where does Anthropic's Messages API put the system prompt?

  1. In the URL
  2. In a separate top-level system field
  3. In the API key
  4. Nowhere; it is not supported
Show answer

Answer: In a separate top-level system field

Anthropic separates the system prompt from the messages list.

Lesson: Anthropic and OpenAI Side by Side

Messages, Parameters and Output

5. Why read the stop reason as well as the text?

  1. It contains the API key
  2. It tells you if the answer was cut off or a tool was requested
  3. It is the model name
  4. It is decorative
Show answer

Answer: It tells you if the answer was cut off or a tool was requested

A truncated or tool-requesting response must be handled differently from a finished one.

Lesson: Your First Call With Each SDK

6. To continue a conversation, what must you send?

  1. Nothing; the server remembers
  2. Only the newest message
  3. Only the API key
  4. The relevant history plus the new message
Show answer

Answer: The relevant history plus the new message

The API is stateless; context is whatever you send.

Lesson: Roles, System Prompts and Conversation History

7. What does a stop reason of max_tokens (or length) tell you?

  1. The reply was cut off at your limit
  2. The reply is perfect
  3. The key is invalid
  4. The model refused
Show answer

Answer: The reply was cut off at your limit

Truncated output may be incomplete or invalid JSON; handle it explicitly.

Lesson: Parameters: max_tokens, Temperature, Top-p, Stop

8. Why validate JSON even when using a structured-output feature?

  1. It is forbidden to trust models
  2. JSON cannot be parsed
  3. Values can still be wrong or outside your business rules, and failures happen
  4. It makes replies shorter
Show answer

Answer: Values can still be wrong or outside your business rules, and failures happen

Schema validity is not the same as correctness for your rules.

Lesson: Structured Output and Validating Replies

Streaming Responses

9. What does streaming mainly improve?

  1. The token price
  2. The accuracy of answers
  3. Perceived latency, because text appears while it is generated
  4. The key security
Show answer

Answer: Perceived latency, because text appears while it is generated

Users see the first words sooner even if total time is similar.

Lesson: How Streaming Works

10. Why cancel the upstream request when the user presses stop?

  1. So you stop paying for tokens nobody will read
  2. To delete the key
  3. To speed up the model
  4. It is required by HTTP
Show answer

Answer: So you stop paying for tokens nobody will read

Generation continues and bills until the request is closed.

Lesson: Streaming in Applications: UI, Backends and Cancellation

Tool Use (Function Calling)

11. Who actually executes a tool call?

  1. The browser
  2. The model
  3. The provider's GPU
  4. Your application code
Show answer

Answer: Your application code

The model only requests the call; you decide whether and how to run it.

Lesson: How Tool Use Works

12. How does a tool_result block link to the request?

  1. Through the API key
  2. Through tool_use_id matching the tool_use block id
  3. Through the model name
  4. It does not link
Show answer

Answer: Through tool_use_id matching the tool_use block id

Each result must reference the id of the call it answers.

Lesson: A Complete Tool Loop With the Anthropic SDK

13. In OpenAI tool calls, what type is function.arguments?

  1. An already validated Python dict
  2. A JSON string you must parse and validate
  3. A number
  4. A file
Show answer

Answer: A JSON string you must parse and validate

Arguments are model-generated text; never trust them unchecked.

Lesson: A Complete Tool Loop With the OpenAI SDK

14. Where should "only this user's data" be enforced?

  1. Nowhere
  2. Only in the system prompt
  3. Only in the model's memory
  4. In the tool code, using the authenticated user id
Show answer

Answer: In the tool code, using the authenticated user id

Code-enforced rules cannot be talked around by a clever prompt.

Lesson: Designing and Securing Tools

Reliability: Errors, Retries and Limits

15. Which error should you NOT retry?

  1. 400 invalid request
  2. 429 rate limited
  3. 503 overloaded
  4. A dropped connection
Show answer

Answer: 400 invalid request

Repeating a malformed request just fails again; fix the request.

Lesson: Error Types and Which to Retry

16. What is the purpose of jitter in backoff?

  1. Encrypting requests
  2. Making retries faster
  3. Spreading retries out so clients do not all return at once
  4. Choosing the model
Show answer

Answer: Spreading retries out so clients do not all return at once

Randomised waits prevent synchronised retry storms.

Lesson: Exponential Backoff With Jitter

17. Why cap concurrency instead of sending all requests at once?

  1. To make tokens free
  2. Because HTTP forbids it
  3. To stay under rate limits and avoid a wall of 429 errors
  4. To avoid keys
Show answer

Answer: To stay under rate limits and avoid a wall of 429 errors

Bounded parallelism respects quotas and smooths load.

Lesson: Rate Limits, Concurrency and Timeouts

18. What does a circuit breaker do after repeated failures?

  1. Pauses calls for a while to avoid piling up timeouts
  2. Deletes the API key
  3. Doubles the retries
  4. Switches off logging
Show answer

Answer: Pauses calls for a while to avoid piling up timeouts

Failing fast protects your system and gives the dependency time to recover.

Lesson: Fallbacks and Graceful Degradation

Cost, Tokens and Performance

19. What counts as input tokens on every request?

  1. Only the reply
  2. Only the newest user word
  3. Nothing
  4. System prompt, tool definitions and conversation history
Show answer

Answer: System prompt, tool definitions and conversation history

Everything you send is billed, including repeated context.

Lesson: Tokens, Pricing and Estimating Cost

20. Why record usage with feature and user labels?

  1. To make the model faster
  2. To find which features and customers drive cost
  3. To avoid keys
  4. Because the API requires it
Show answer

Answer: To find which features and customers drive cost

Attribution turns a single bill into actionable information.

Lesson: Tracking Usage and Setting Budgets

21. How should a prompt be arranged to benefit from prompt caching?

  1. Changing content first
  2. Stable content first, changing content last
  3. Random order
  4. Caching needs no arrangement
Show answer

Answer: Stable content first, changing content last

Caches match on an identical prefix, so the shared part must come first.

Lesson: Reducing Cost and Latency: Caching, Batching, Model Choice

Security, Testing and Production

22. What is the best protection against logging a key?

  1. Put it in the URL
  2. Log everything and hope
  3. Print it once for convenience
  4. Never include it in anything you log, and redact as a safety net
Show answer

Answer: Never include it in anything you log, and redact as a safety net

Prevent the leak at the source; redaction catches mistakes.

Lesson: Protecting Keys and Logs

23. What should you do with model-generated text before showing it in a web page?

  1. Escape it (and never execute it)
  2. Insert it as raw HTML
  3. Run it with eval
  4. Nothing
Show answer

Answer: Escape it (and never execute it)

Model output can contain scripts; treat it as untrusted text.

Lesson: Treating Model Output and Inputs as Untrusted

24. What is a good first step before sending customer data to a provider?

  1. Ignore the terms
  2. Send everything for context
  3. Check data-retention terms, send the minimum and redact personal data
  4. Disable logging only
Show answer

Answer: Check data-retention terms, send the minimum and redact personal data

Data minimisation and clear terms reduce legal and privacy risk.

Lesson: Privacy, Data Handling and Compliance

25. Why test with a fake server instead of the real API in unit tests?

  1. Real APIs are forbidden in tests
  2. Fakes measure answer quality
  3. Tests are fast, free, deterministic and need no keys
  4. Fakes train the model
Show answer

Answer: Tests are fast, free, deterministic and need no keys

Use fakes for your integration logic and a separate eval set for quality.

Lesson: Testing Your Integration With a Stand-In Server

Putting It Together

26. Why does the backend, not the browser, call the provider?

  1. So the API key stays secret and users are authenticated by you
  2. Browsers cannot send JSON
  3. It makes tokens free
  4. Backends are faster than browsers
Show answer

Answer: So the API key stays secret and users are authenticated by you

Anything in the browser can be extracted, including keys.

Lesson: Case Study: A Support-Reply Drafting Endpoint

27. Your call returns 429 Too Many Requests. What is the right response?

  1. Give up and delete the data
  2. Retry immediately in a tight loop
  3. Change the API key
  4. Wait with exponential backoff and jitter, honour retry-after, then retry a limited number of times
Show answer

Answer: Wait with exponential backoff and jitter, honour retry-after, then retry a limited number of times

429 is transient; polite, bounded retries usually succeed.

Lesson: Revision: Cheat Sheet and Self-Check

28. A reply stopped with stop_reason "max_tokens". What does this mean?

  1. The model finished perfectly
  2. The output was truncated at your limit and may be incomplete
  3. The key expired
  4. A tool was requested
Show answer

Answer: The output was truncated at your limit and may be incomplete

Truncation must be handled: raise the limit, shorten the request or continue.

Lesson: Revision: Cheat Sheet and Self-Check

29. Which is the safest place to enforce "a user may only see their own orders" in a tool-using assistant?

  1. In the system prompt only
  2. In the tool code, filtering by the authenticated user id
  3. In the model's temperature
  4. In the browser
Show answer

Answer: In the tool code, filtering by the authenticated user id

Server-side code enforcement cannot be bypassed by clever prompting.

Lesson: Revision: Cheat Sheet and Self-Check

← Back to the course