Anthropic SDK
Use the Anthropic Python and TypeScript SDKs with Boundless through POST /v1/messages: install, base URL and key, streaming and tool use.
The gateway serves the Anthropic Messages API at POST /v1/messages. The Anthropic SDKs work against it with a new base URL and a Boundless key.
Install#
Base URL and key#
The Anthropic SDKs add /v1/messages themselves, so give them the gateway root: https://api.inference.boundless.network, with no /v1. The gateway takes the key as x-api-key, which is what these SDKs send, or as Authorization: Bearer.
Use a model ID exactly as the models table lists it. Any model there works on Messages, not only the Claude models.
Make a request#
max_tokens is required and must cover thinking plus the reply. Give reasoning models 1024 or more.
Stream the reply#
The gateway sends the standard Anthropic server-sent events.
Call a tool#
The model answers with a tool_use block. You run the function and send a tool_result block back.
Tool calling covers the other wire formats.
Known differences#
- Responses are Anthropic-shaped:
contentblocks,stop_reason,tool_use, andusagewithinput_tokensandoutput_tokens. - Errors use the Anthropic shape,
{"type": "error", "error": {"type", "message"}}, with nocodeand noparam. Match onerror.type. See Errors. POST /v1/messages/count_tokenscounts input tokens without running the request.- Credits that run out return
402. The errortypeisbilling_error, and the SDK does not retry it. - Anthropic-hosted features are not served. See API Compatibility.
- After a
502, a timeout or a dropped stream, checkGET /v1/requests/{id}before you resend. See Retrying safely.