Claude · Coding

API integration

Give Claude current docs so it doesn't invent fields, generate a typed client, and make every API failure visible.

Claude for API integration

Two different jobs

This lesson covers two situations that need different handling. If you're connecting your code to someone else's API, Claude works best from that API's current docs and schema, because its memory of a third-party API can be out of date. If you're calling Claude itself, start with Anthropic's official SDKs, which come in Python, TypeScript, C#, Go, Java, PHP and Ruby, with an ant command-line tool for scripts. They already give you types, streaming, error handling and retries, so you don't need a generated client. Install the Python one with pip install anthropic, or the TypeScript one from the @anthropic-ai/sdk package.

Work in this order

Most integration trouble comes from doing these steps out of order. Give Claude the real docs first, so nothing is written from memory. Next, list the failures and decide what happens for each, before any happy-path code exists. Then generate types from the schema and have Claude write a thin client around them, with a validator where responses arrive. Finally, sweep the result for places where an error can vanish without anyone hearing about it. The last step matters most for code that runs unattended, such as cron jobs and webhooks, where nobody is watching a console.

Frequently asked
How do I get Claude to use an API correctly?

Give it the current docs for the endpoints you need, and tell it to use only what appears there and to say so if something is missing. In Claude Code, save the page to a file and reference it with @.

Why does Claude make up API endpoints?

Without the docs, it works from memory, which is a snapshot that may be out of date and may blend similar APIs. Giving it the current reference and forbidding anything not in it prevents most of this.

Does the Anthropic SDK retry failed requests?

Yes. Anthropic's docs say the Python SDK retries connection errors and 408, 409, 429 and 5xx responses twice by default, with exponential backoff. You can change this with the max_retries option, and setting it to 0 turns retries off.

What does a 529 error mean on the Claude API?

It's an overloaded_error, meaning the API is temporarily overloaded across all users. It can also arrive inside a stream after a 200 response. Retrying with backoff is reasonable, and the official SDKs do that for you by default.

Why do I keep getting a 429 from the Claude API?

If the response has no retry-after header and error.details.error_code is enforced_spend_limit_reached, your organization hit its tier's monthly spend cap. Retries keep failing until access resumes at 00:00 UTC on the first of next month, unless you move up a tier.