polygate logopolygate

Provider

Anthropic

Claude models.

Quick start

import polygate
 
response = polygate.chat(
provider="anthropic",
model="claude-sonnet-4-5",
messages=[{"role": "user", "content": "Say hi in one word."}],
)
 
print(response.content) # "Hi!"
print(response.usage) # Usage(prompt_tokens=..., completion_tokens=...)

Names

Any of these work as provider. They all reach the same adapter, so pick whichever reads best in your code.

anthropicclaude

Configuration

VariableHolds
ANTHROPIC_API_KEYyour API key

Any of these may hold a comma-separated list. polygate rotates across them, parks a rate-limited one for its Retry-After, and drops one the provider rejects — so a key pool is configuration, not code.

Endpoint

https://api.anthropic.com/v1/messages

Pass base_url to point the same wire format somewhere else — a proxy, a regional endpoint, or a gateway in front of it.

Models

Examples that work today. Model names change; the provider's own list is the authority.

claude-sonnet-4-5claude-opus-4-5claude-haiku-4-5

Things worth knowing

  • Anthropic takes the system prompt as its own top-level field. polygate moves any system message out of the list for you, so the same message array works here as everywhere else.
  • max_tokens is required by the Messages API. polygate supplies a default when you omit it.

Batch

Anthropic has an offline batch tier at roughly half price. See Batching & concurrency.

Something wrong or missing here? Open an issue.