ClaudeAPI integrationLevel 2: Context

How Do You Stop Claude Inventing API Fields?

Give it the current docs for the endpoints you need, and tell it not to use anything that isn't in them. A model's memory of an API is a snapshot, and APIs change. In Claude Code, save the page into your repo and reference it with @, or have Claude fetch the raw page with curl.

Prompt to copy
Here's the documentation for the endpoints I need, copied from [URL] on [date]:

[paste routes, parameters, request and response shapes, auth and error codes]

Write a client in [language] at [path] that covers: [operations].

- Use only endpoints, parameters and fields that appear above. If I need something that isn't there, stop and tell me. Don't fill gaps from memory.
- Handle auth as documented.
- Map the documented error codes to typed errors.
- Next to each request, add a comment naming the docs section it came from.

Then list anything in these docs that looked ambiguous, and anything you'd normally expect from an API like this that you didn't find.
From older codereturns a 400 today
  • thinking type enabled
  • A prefilled assistant message
  • tool_choice any or tool
From the current docswhat the page says to use
  • thinking type adaptive, plus effort
  • output_config.format
  • tool_choice auto, with strict tools
From Anthropic's API errors page, for Opus 5.5 and Sonnet 5.5. Claude can't know about changes like these from older code unless you show it the docs.
  • 100,000Characters read per call
  • 15 minResponse cacheby default
WebFetch limits. Source: Anthropic's Claude Code tools reference, checked 6 November 2026. For exact field names, use a saved file or curl.

Try it now

  1. 1Save the page you need, for example curl -s https://platform.claude.com/docs/en/api/errors.md -o docs/claude-errors.md.
  2. 2In Claude Code, paste the prompt and replace the docs placeholder with @docs/claude-errors.md.
  3. 3Then ask list every endpoint and field your client uses, and the line in the docs file where each appears. Anything without a line is a guess.
  4. 4Make one real call against a test account. It worked if you don't get a 400 or 404 caused by a wrong field or path.

Use it when

Any integration with a service whose docs you can copy: REST endpoints, SDK methods, webhook payloads and model APIs. It matters most for new or fast-changing APIs.

Skip it when

Stable, widely known interfaces such as fetch, where recall holds up (rule of thumb, not a vendor figure). Don't paste a whole reference either. Anthropic's developer docs index alone listed 886 English pages when checked on 6 November 2026, so pick the endpoints you need.

Why it works

Claude's own API shows how fast memory goes stale. Against Opus 5.5 and Sonnet 5.5, Anthropic's errors page says thinking: {"type": "enabled"}, a prefilled assistant message and a forced tool_choice all return a 400. The older output_format parameter does too, unless you send its beta header. How you hand over the docs matters as well. Claude Code's WebFetch tool usually runs a prompt against the page in a separate model call, and Claude gets that result, not the raw page. The docs call this lossy by design, so an exact field name can get lost. For exact names, use a saved file or curl.

Example

Say you ask for a Claude client that returns JSON, with no docs attached. A model recalling older code may well reach for a prefilled assistant message, which Anthropic's errors page says now returns a 400. Attach the structured outputs page instead, and the request shape to expect is output_config: { format: { type: "json_schema", schema: {...} } }. Your schema also has to set additionalProperties to false on objects, which is the sort of detail memory tends to lose.

Going further

Many docs sites now publish plain-text versions. https://platform.claude.com/llms.txt indexes Anthropic's developer docs with a .md address for each page, and https://code.claude.com/docs/llms.txt does the same for Claude Code. Have Claude read the index, then only the pages it needs. WebFetch reads up to 100,000 characters per call, caches responses for 15 minutes, and refuses localhost and hostnames without a dot, so use curl for an internal docs server. Treat what comes back as data, too. Some vendor pages now carry instructions aimed at AI agents, so read what Claude plans to do before you approve it.

Common mistakes

  • Trusting a WebFetch summary for exact field names. The docs say a result claiming a page doesn't mention something may only mean the prompt didn't ask about it.
  • Attaching a giant reference with @. A file is included only when it fits the Read tool's limit, 25,000 tokens by default, and a text file over 256KB isn't included at all.
  • Leaving out the error table, so the client treats every failure the same way.
  • Saving docs without a date. A local copy goes stale too, so keep the URL and the date at the top of the file.

Sources

Checked 6 November 2026. Products change often, so confirm details with the vendor.

Related

Beyond the course