Skip to main content

Adding Models

This section explains the steps to add Anthropic models and configure the required access controls.
1

Select Anthropic as the provider

From the TrueFoundry dashboard, go to AI Gateway > Models, click Add Model and choose To New Provider Account. Select Anthropic from the provider list.
Add Provider Account page listing the supported model providers

Choose a provider in Add Provider Account

2

Add Anthropic Account Details

Give a unique name to your Anthropic account and complete the form with your Anthropic authentication details (API Key). For Claude subscription passthrough (Team, Pro, Max — see Claude Code → Authentication by plan), leave the API key empty. Under advanced settings, you can optionally set a Base URL to route requests through a proxy. It must include the version path, for example https://my-proxy.example.com/v1. If unset, requests go to https://api.anthropic.com/v1.
Strongly prefer Workload Identity Federation when you use a TrueFoundry SaaS gateway. It connects without an API key and uses short-lived tokens instead of a long-lived secret.
Anthropic Configure Account form in the provider account setup drawer

Configure Account for Anthropic

3

Add Models

Select the model from the list. If you see the model you want to add in the list of checkboxes, we support public model cost for these models.
If the model you need is not listed, click Add Model Manually in the banner below the list and enter its display name, model ID and model types.
TrueFoundry AI Gateway supports all text and image models in Anthropic.The complete list of models supported by Bedrock can be found here.
4

Save and grant access

Click Test Credentials to check the account against the selected models, or click Save without Testing. To keep the account in Git instead, click Apply using YAML and apply the generated spec with tfy apply.To let other users, teams or virtual accounts use or manage these models, open Manage Accounts, click ⋮ on the account and choose Access Control > Grant Access. See Access control.

Authenticate with Workload Identity Federation

For now, Workload Identity Federation for Anthropic and OpenAI works only on TrueFoundry SaaS gateways (gateway.truefoundry.ai). Support for customer-hosted (hybrid) and self-hosted gateways is planned.
With Workload Identity Federation (WIF), the gateway calls Anthropic with short-lived access tokens instead of an API key. TrueFoundry signs a JWT for your tenant; Anthropic trusts that JWT and returns an access token. You set up the trust once in the Claude Console, then paste four IDs into TrueFoundry: the Organization ID, Workspace ID (wrkspc_…), Service Account ID (svac_…), and Federation Rule ID (fdrl_…). None of them are secret.
A federation rule or mapping trusts your whole TrueFoundry tenant, not one provider account: the JWT’s subject is tfy-ai-gateway:tenant:<tenant-name>. Anyone who can manage an Anthropic or OpenAI provider account in your tenant can point it at any rule or mapping that trusts the tenant, and anyone signed in to your tenant can test those IDs by calling the gateway’s test endpoint directly. Give each rule or mapping only the access your whole tenant may use.

What you’ll do

The examples use a tenant named acme.
  1. In TrueFoundry, open a new Anthropic provider account on the Workload Identity Federation tab and copy the Issuer URL, Subject, and Audience.
  2. In the Claude Console, register that issuer, then create a workspace, service account, and federation rule that use those three values.
  3. Copy the resulting Organization ID, Workspace ID, Service Account ID, and Federation Rule ID back into TrueFoundry, then test and save.

Copy the values from TrueFoundry

Go to AI Gateway > Models, click Add Model, choose To New Provider Account and select Anthropic. Name the account, turn on Auth Data and select the Workload Identity Federation tab. Copy the Issuer URL, Subject and Audience, and keep the form open — you’ll paste Anthropic’s IDs into the empty fields below them. Every provider account in your tenant shows the same issuer and subject.
Anthropic account form with the Workload Identity Federation tab selected, showing the issuer URL, subject and audience with Copy buttons, and the four ID fields

The Workload Identity Federation tab of an Anthropic provider account

Set up Anthropic

Do these steps in the Claude Console. Paste the three values you copied from TrueFoundry into the matching fields below.
1

Register the issuer

On the Workload identity page, go to Issuers > Register issuer:
  • Name: for example truefoundry-acme.
  • Issuer URL (iss claim): paste the Issuer URL from TrueFoundry, exactly, with no trailing slash.
  • JWKS source: OIDC discovery. Leave the discovery base URL and CA certificate empty.
  • Enforce single-use tokens: Off. It’s on by default. The gateway reuses each signed JWT for up to 5 minutes, so with it on, Anthropic rejects the repeats and requests fail.
  • Maximum token lifetime (hours): 1 or more. The gateway’s JWTs are valid for 1 hour.
Claude Console Register issuer dialog with Name, Issuer URL, JWKS source set to OIDC discovery, the optional discovery base URL and CA certificate, and the Enforce single-use tokens setting outlined

Register issuer. Turn off Enforce single-use tokens (outlined), which is on by default. The maximum token lifetime is below it.

2

Create a workspace

On the Workspaces page, click Create workspace. A workspace of its own lets you set rate and spend limits for gateway traffic and see its usage. Note the Workspace ID (wrkspc_…) — you’ll paste it into TrueFoundry later.
3

Create a service account

On the Service accounts page, click Create service account. Name it, for example truefoundry-gateway, give it the Developer organization role, and add the new workspace under Workspaces. Don’t choose Admin: an Admin service account lets a federation rule grant organization-admin scopes. Note the Service Account ID (svac_…) — you’ll paste it into TrueFoundry later.
Claude Console Create service account dialog with Name, Description and Organization role set to Developer

Create service account with the Developer role

4

Create the federation rule

On the Workload identity page, go to Rules > New rule:
Claude Console Create federation rule dialog with Rule name, Issuer, Pattern match, Subject pattern, Additional claim conditions and Expected audience

Create federation rule: the issuer and match conditions

Claude Console Create federation rule dialog with the target service account, Enable in all workspaces, Workspaces, OAuth scope workspace:developer and Token lifetime

Create federation rule: the target and authorization. Values specific to the capture are hidden.

Never choose org:admin: it grants admin access to your whole Anthropic organization, and TrueFoundry doesn’t check the scope of the tokens Anthropic issues. To limit tokens to inference, create the rule with the workspace:inference scope through Anthropic’s Admin API instead.

Copy the IDs from Anthropic

Copy these four IDs — they are what you paste into TrueFoundry. Copy them as text rather than reading them off the screen: O and 0 are easy to confuse.

Add the account in TrueFoundry

Go back to the form from Copy the values from TrueFoundry.
1

Enter the IDs

Paste the Organization ID, Federation Rule ID, Service Account ID, and Workspace ID you copied from Anthropic. Leave Base URL (under Show advanced fields) empty: with Workload Identity Federation, only https://api.anthropic.com/v1 is accepted.
2

Select models

Click Continue to Integrations and select models as in Adding Models.
3

Test and save

Click Test Credentials to run a real token exchange with the provider. It works before you save, so you can fix the provider setup first. In the TrueFoundry UI, testing needs the same permission as saving. Then save the account, or click Apply using YAML to keep it in Git and apply it with tfy apply.
Anthropic provider account

Revoke access

Archive the federation rule in the Claude Console. New exchanges then fail. Access tokens Anthropic has already issued keep working until they expire, within about 1 hour.

Troubleshooting

Anthropic returns the same 401 (authentication_error) for every rejected JWT. The reason is in the Claude Console’s authentication history, for example match_subject_prefix when the subject doesn’t match the rule. See also Anthropic’s Troubleshoot a failed exchange.
Anthropic can’t fetch the JWKS. Check that the issuer URL is exactly the one TrueFoundry shows, then check that the issuer is reachable. After repeated failed fetches, Anthropic pauses JWKS polling for the issuer. Once the issuer works again, re-enable polling by updating the issuer with jwks_polling_disabled: false (see Anthropic’s issuers API).
Check the deny reason in the authentication history. Compare the rule’s subject pattern and expected audience with the values TrueFoundry shows. Check that the rule is enabled in the workspace whose ID you entered, and that the service account belongs to that workspace.
Enforce single-use tokens is probably on for the issuer — for example when a second Anthropic account in the same tenant fails intermittently. Turn it off.
Anthropic didn’t accept the IDs. The error includes Anthropic’s message when it sends one. Copy the four IDs again.
Anthropic rate-limited the exchange, or its token endpoint failed. Retry after a short wait.
  • Requests on a customer-hosted (hybrid) or self-hosted gateway fail with Workload identity federation for Anthropic and OpenAI is only supported on TrueFoundry SaaS gateways. — send these requests through a TrueFoundry SaaS gateway, or use an API key provider account on that gateway.
  • Saving the provider account fails with a 400 error: Workload identity federation for Anthropic and OpenAI is only supported on TrueFoundry SaaS. — your control plane isn’t TrueFoundry SaaS. Use an API key provider account there.

Check that the issuer is reachable

Use this when Anthropic can’t verify TrueFoundry’s tokens. Anthropic fetches the signing keys from your issuer URL to check each token, so if that URL doesn’t serve them, every exchange fails. Run these checks before you change the issuer or the federation rule. They don’t need any credentials. Fetch your tenant’s discovery document:
Fetch the discovery document
A working issuer returns JSON whose issuer is your issuer URL and whose jwks_uri is <issuer URL>/.well-known/jwks.json. Both documents are public. A 404 means the tenant name in the URL is wrong or the tenant isn’t active. A 503 is temporary, for example while the signing keys load, so retry after a short wait.

How it works

  1. The gateway signs a JWT that names your TrueFoundry tenant, valid for 1 hour, and sends it with the account’s IDs to the provider’s token endpoint.
  2. The provider fetches the public signing keys from your tenant’s issuer URL, verifies the JWT, and checks it against your federation rule (Anthropic) or mapping (OpenAI).
  3. The provider returns an access token valid for about 1 hour, which the gateway uses for model calls. Once half of the token’s life has passed (30 minutes before expiry for a one-hour token), the next request starts a new exchange in the background, and requests keep using the current token meanwhile.
If a refresh fails, for example because the provider or the issuer is briefly unavailable, the gateway keeps using the current token and retries with backoff until 30 seconds before it expires. After that, a failed exchange fails the request with an error that names the provider account. The gateway never falls back to an API key.
The JWT is signed with RS256 and carries exactly these claims, with no user, email or role information. exp is 1 hour after iat, and jti is a new random ID for each JWT. The gateway reuses a signed JWT for up to 5 minutes, so several exchanges can carry the same jti.
Decoded JWT claims
For OpenAI, aud is the account’s Audience, or https://api.openai.com/v1 if it’s empty.

Inference

After adding the models, you can perform inference using an Anthropic-compatible API via the Playground or by integrating with your own application.
For Anthropic streaming requests, AI Gateway supports fallback on overloaded_error before generation begins. The AI Gateway waits for the first non-empty stream chunk; if it receives an overloaded_error before that first chunk, it automatically falls back to the next configured model. Learn more in Anthropic Stream Overload Fallback.
To enable Anthropic beta features, send x-tfy-anthropic-beta with a comma-separated list of beta tokens. When this header is present, it replaces every other client beta source — including the anthropic-beta header and body anthropic_beta — and is not merged with them. The only override is a virtual model’s headers_override of x-tfy-anthropic-beta itself; setting anthropic-beta in the override does not replace it. See Header overrides.
Anthropic’s Messages API requires max_tokens. If your request omits it, the AI Gateway sends a default of 2048 tokens so the request does not fail. Responses longer than that are truncated with finish_reason: "length", so set max_tokens explicitly for long-form generations. See max_tokens defaults per provider.
Code Snippet and Try in Playground Buttons for each model

Supported APIs

Once your Anthropic model account is configured, the following API surfaces are available through the AI Gateway. The table below summarizes each endpoint alongside platform feature support (tracing, cost tracking).
Legend:
  • ✅ Supported by provider and TrueFoundry
  • Supported by Provider, but not by TrueFoundry
  • Provider does not support this feature
The chat completions endpoint is the most widely used — it supports streaming, tools, multimodal input (images, PDF), structured JSON outputs, prompt caching and extended thinking. Full provider capability matrix: Chat Completions API.
Python
Set stream=True to start streaming responses and iterate over delta chunks. You may defensively check that chunk.choices is non-empty and delta.content is not None.
Python
Advertise a tool, hand the model’s tool_calls back as a tool role message, then request the final response. Use tool_choice to force the model to call a specific tool when you need deterministic behaviour.
Python
Claude 3+ models support image inputs via the image_url content part.The URL can be a public HTTP URL or an inline data:image/...;base64,... URI. For self-contained examples we recommend the inline form.
Python
Claude models support PDF documents via the file content type with base64 encoding.
Python
Use response_format={"type": "json_schema", ...} to force the model to return data matching a JSON schema. Claude 4.5/4.6 models use native JSON schema support; older models use a tool-conversion fallback.
Anthropic does not support numeric constraint parameters (ge, le,minimum, maximum) in schemas. If you use Pydantic-generated schemas, strip these constraints before passing them through.
Python
Anthropic requires explicit cache_control on content blocks you want cached (unlike OpenAI’s automatic caching). Cached tokens appear as cache_creation_input_tokens (first call) and cache_read_input_tokens (subsequent calls) in the usage response.
Minimum cacheable prefix: 1024 tokens for Claude Sonnet/Opus, 2048 tokens for Claude Haiku. Prompts shorter than this will accept the cache_control hint but won’t actually be cached.
Python
Claude Sonnet 3.7, Claude 4, and Claude 4.5 series models support extended thinking. Use the reasoning_effort parameter — the AI Gateway translates it into Anthropic’s native thinking parameter format.
The AI Gateway maps reasoning_effort to a thinking.budget_tokens ratio of the request’s max_tokens: none = 0%, low = 30%, medium = 60%, high = 90%.
The response includes reasoning_content (plain text) and thinking_blocks (structured blocks with cryptographic signatures required for multi-turn reasoning continuity).
Python
Always echo thinking_blocks exactly as returned when continuing a conversation. Blocks with missing or modified signature fields are rejected by Anthropic.
Anthropic’s native Messages API (/messages) is also exposed through the AI Gateway, letting you use the official anthropic Python SDK directly. You get the same gateway features — routing, logging, rate-limiting, budget management — as with the OpenAI-compatible interface. Full docs: Messages API, Native SDK Support
The AI Gateway accepts both Anthropic SDK auth patterns and translates internally:
  • api_key=TFY_API_KEY - SDK sends the x-api-key header
  • auth_token=TFY_API_KEY — SDK sends the Authorization: Bearer header
Either works; the request body is identical. api_key is the idiomatic Anthropic SDK pattern - use it unless you have a reason to send a Bearer token.
Python
Use .messages.stream() and iterate over text_stream for incremental output.
Python
Upload, list, retrieve, and delete files held by the AI Gateway. The AI Gateway translates the OpenAI-compatible Files API into Anthropic’s native Files API automatically. Full docs: Files API.
The Files API requires the x-tfy-provider-name header on the client so the AI Gateway can route the request to the right Anthropic model account.
File content retrieval (files.content) only works for files created by skills or the code execution tool. User-uploaded files cannot be downloaded back — you can only list metadata and delete them.
Python