Skip to main content
The LLM Gateway is in beta.
The standard LLM Gateway API supports three request and response formats. Choose the format your application already uses. Then call models with your own provider keys or Gateway Credits through the same endpoint.

Compare API formats

On LangSmith Cloud in the US region, each format uses the following base URL and endpoint. For other regions, BYOC data planes, and self-hosted installations, see Check availability.
All formats authenticate with a workspace-scoped LangSmith API key. For key types, permissions, and the header each client sends, see Authenticate to the LLM Gateway.

Understand translation behavior

The endpoint determines the format your application sends and receives. The model ID determines the upstream provider.
  • When the provider supports the selected format natively, the gateway preserves that format.
  • Otherwise, the gateway translates the request into a format supported by the provider and translates the response back, including streaming responses.
  • Translation can reject fields that cannot be represented in the target provider format. Use direct model access when provider-native behavior is required.
Every request resolves the same provider secrets, policies, and tracing configuration regardless of format.

Use prompt caching

How you request prompt caching depends on the format you send and the model you call:
  • OpenAI models: OpenAI caches prompts automatically. To control cache lifetime or breakpoints, use OpenAI’s caching fields, such as prompt_cache_options or prompt_cache_retention. Which fields and values each model accepts is set by OpenAI. For details, see the OpenAI prompt caching guide.
  • Anthropic models in Messages format: Use Anthropic’s cache_control field. For details, see the Anthropic prompt caching guide.
  • Anthropic models in Chat Completions or Responses format: Set any of prompt_cache_options, prompt_cache_retention, or prompt_cache_key. The gateway turns on Anthropic prompt caching with Anthropic’s default five-minute cache lifetime. It does not carry over a requested lifetime, retention, or breakpoint mode.
  • OpenAI models in Messages format: The gateway drops cache_control fields. OpenAI’s automatic caching still applies.

Send a request

Each format has its own request shape. For example, Chat Completions takes messages, Responses takes input, and Messages requires max_tokens. Replace <MODEL_ID> with a model ID:
For the full request and response schemas, see the OpenAI Chat Completions API, the Anthropic Messages API, and the OpenAI Responses API.
For the same request in Python or TypeScript, open the Simulator tab in the LLM Gateway, select the format and language, then click the copy icon. The copied code already uses your deployment’s gateway URL. For details, see Send your first LLM Gateway request.

Choose a model ID

The model ID selects the provider and the credential that pays for the call. Model IDs work the same way in every format:
  • Your own provider key: <provider>/<model>, such as openai/gpt-5.4-mini or azure/<deployment-name>. The gateway calls the provider with the provider key stored in your workspace.
  • Gateway Credits: a hosted model slug, such as moonshotai/kimi-k3. Gateway Credits bill LangChain-hosted models to your LangSmith account, with no provider key required.
  • Saved model configuration: custom/<name>. The gateway uses the provider, model, and credentials from the saved model configuration.

List models

Call GET /v1/models to list the model IDs your workspace can call. The gateway returns a single OpenAI-compatible list:
Pass an ID exactly as shown. The list omits providers without a configured provider key and models that your model access policies block. Saved model configurations do not appear in the list.

Read response metadata

The gateway adds an X-LangSmith-Gateway-Metadata header to its responses. The header is a JSON object that describes how the gateway handled the request, such as the provider and model it called and whether a policy blocked the request. It contains no credentials or prompt and response content. To tell a gateway decision from a provider error, read two fields: outcome says how the request ended, such as success, blocked, or upstream_error, and error_source says whether a failure came from the caller (request), the provider (upstream), or the gateway (internal). When a fallback chain runs, the header also lists each attempt. LangChain chat models in Python (langchain-openai>=1.6.7 or langchain-anthropic>=1.7.5) attach the header to the model’s run, so with tracing on, the same details appear in the run’s Gateway section.

Fix request errors

To tell whether the gateway or the provider returned an error, read the outcome and error_source fields in the response metadata.
For 401 and 403 errors, see Fix authentication errors. For 424 errors, see Fix provider credential errors.

See also