Learn how to use TrueFoundry’s unified Chat Completions API to interact with models from multiple providers through a consistent interface.
TrueFoundry AI Gateway provides a universal API for all supported models via the standard OpenAI /chat/completions endpoint. This unified interface allows you to seamlessly work with models from different providers through a consistent API.API Reference:POST /chat/completions
You can use the standard OpenAI client to send requests to the AI Gateway:
from openai import OpenAIclient = OpenAI( api_key="your_truefoundry_api_key", base_url="{GATEWAY_BASE_URL}")response = client.chat.completions.create( model="openai-main/gpt-4o-mini", # this is the truefoundry model id messages=[{"role": "user", "content": "Hello, how are you?"}])print(response.choices[0].message.content)
model: TrueFoundry model ID in the format provider_account/model_name (available in the LLM playground UI)
See Integrate with code for instructions on obtaining these values.For using native provider SDKs (OpenAI, Google Gen AI, Anthropic, boto3), see Native SDK Support.
System prompts set the behavior and context for the model by defining the assistant’s role, tone, and constraints:
response = client.chat.completions.create( model="openai-main/gpt-4o-mini", messages=[ {"role": "system", "content": "You are a helpful assistant that specializes in Python programming."}, {"role": "user", "content": "How do I write a function to calculate factorial?"} ])
max_tokens is optional in the OpenAI-compatible API, but what happens when you omit it depends on the provider integration. Anthropic’s Messages API requiresmax_tokens, so for integrations that speak that format the AI Gateway supplies a default rather than letting the request fail.
Provider integration
If you omit max_tokens
Effective limit
Anthropic
Gateway sends a default
2048 tokens
AWS Bedrock Mantle (Claude models)
Gateway sends a default
2048 tokens
AWS Bedrock (Converse)
Gateway sends nothing; Bedrock applies its own per-model default
Model-dependent — 4096 for Claude Opus and Sonnet
All other providers
Gateway sends nothing; the provider’s own default applies
Provider-dependent
Always set max_tokens explicitly for long-form generations. If you rely on the default, a response can be truncated mid-sentence with finish_reason: "length" and no error — most visibly on Claude Opus and Sonnet via AWS Bedrock, where Bedrock caps output at 4096 tokens despite the models supporting far more.