POST /messages
Provider capabilities
The table below summarizes gateway support for this endpoint by provider.Legend:
- ✅ Supported by Provider and Truefoundry
- Provided by provider, but not by Truefoundry
- Provider does not support this feature
For every gateway endpoint and provider, see Supported APIs.
Anthropic’s Messages API is a powerful interface for interacting with Claude models. When using TruefFundry as your model gateway, you can access this API through a proxy endpoint that handles authentication and routing to the appropriate model.
Prerequisites
To use the Anthropic Messages API through Truefoundry, you’ll need:- TrueFoundry API Key
- Provider account configured in TrueFoundry (Anthropic)
- Python environment with
anthropic sdklibrary installed
Using the Anthropic SDK
The Anthropic Python SDK provides a convenient way to interact with Claude models. Here’s how to configure it to work with the Truefoundry proxy:The gateway accepts both Anthropic SDK auth patterns and translates internally:
api_key=TFY_API_KEY- SDK sends thex-api-keyheaderauth_token=TFY_API_KEY— SDK sends theAuthorization: Bearerheader
api_key is the idiomatic Anthropic SDK pattern - use it unless you have a reason to send a Bearer token.Request Format
When using the Messages API through Truefoundry, your request should follow this format:Response Format
The response from the Messages API will have this structure:Prompt Caching
Prompt caching reuses previously computed prompt prefixes (a largesystem prompt, a shared context document, or a set of tool definitions) so the provider can skip reprocessing the cached portion on subsequent requests. This lowers both latency and cost.
There are two ways to cache with Claude models, and you can combine them:
- Explicit caching — you mark cache breakpoints yourself by adding
cache_controlto individual blocks (asystemblock, a message content block, or atooldefinition). - Automatic caching — you add a single
cache_controlfield at the top level of the request body. The provider then applies the cache breakpoint to the last cacheable block for you and moves it forward as the conversation grows, so you don’t manage breakpoints yourself. Both are provider-side features — see Anthropic’s prompt caching guide.
cache_control to native Claude providers unchanged — it does not strip it (the request is already in Anthropic’s format). The Gateway only strips cache_control for providers that don’t accept it, such as OpenAI or Gemini, which aren’t served natively on the Messages endpoint (see the note below).
Provider support
The Messages endpoint is served natively (in Anthropic’s format) by Anthropic and by Claude models on Bedrock, Google Vertex, and Azure AI Foundry. Explicit caching works on all of them; automatic caching is a provider capability that only some of them offer:Automatic caching (the single top-level
cache_control field) is only supported by the Anthropic API, Claude Platform on AWS, and Microsoft/Azure Foundry. AWS Bedrock and Google Vertex do not support automatic caching — use explicit block-level breakpoints on those providers. For Bedrock specifically, the Gateway drops a top-level cache_control (InvokeModel does not accept it) while forwarding block-level cache_control unchanged.On Bedrock, prompt caching is enabled by default when the request goes through the InvokeModel API (which the Messages endpoint uses for Claude models). You can set explicit cache checkpoints at any point in your request body — across
system blocks, message content blocks, and tool definitions — by attaching cache_control to each block you want to mark. Unlike the Converse-based /chat/completions path, these are forwarded as native Anthropic cache_control rather than rewritten into cachePoint markers.Non-Claude models (and provider-managed providers such as OpenAI or Gemini) are served on the Messages endpoint by translating the request into Chat Completions format. In that translation
cache_control is dropped, but the provider’s own prefix caching still applies transparently, and any cached-token counts are still reported in usage.Explicit caching
Add"cache_control": {"type": "ephemeral"} to any system block, message content block, or tool definition you want cached. This works on every native Claude provider:
Automatic caching
Add a singlecache_control field at the top level of the request body instead of marking individual blocks. The provider applies the breakpoint to the last cacheable block and advances it as the conversation grows — useful for multi-turn chats. This is only supported on Anthropic (direct), Claude Platform on AWS, and Azure AI Foundry:
cache_control hint but are not actually cached:
Cache usage in the response
When caching is active, the responseusage object reports the cached token counts:
cache_creation_input_tokens: tokens written to the cache (first call).cache_read_input_tokens: tokens served from the cache (subsequent calls).