DocsREST API

REST API

Beta. The Langfuse AI Gateway is in public beta and can still change.

You can call the gateway directly over HTTP, for example from a language without an SDK or from a script. Request and response bodies are the model provider's own, so for parameters and fields, see the provider's API reference linked in the endpoints table. This page covers what's specific to the gateway: base URLs, authentication, and endpoints.

Base URLs

RouteBase URL
OpenAIhttps://gateway.cloud.langfuse.com/openai/v1
Anthropichttps://gateway.cloud.langfuse.com/anthropic/v1

These are the EU URLs. For other regions, replace the host with your gateway host.

Gateway hosts

RegionGateway host
EUhttps://gateway.cloud.langfuse.com
UShttps://gateway.us.cloud.langfuse.com
JPhttps://gateway.jp.cloud.langfuse.com
HIPAAhttps://gateway.hipaa.cloud.langfuse.com

A gateway key only works on its own region's host. On self-hosted Langfuse, use the gateway URL your deployment configured (LANGFUSE_AI_GATEWAY_PUBLIC_URL, see Self-hosting the AI Gateway).

Authentication

Every endpoint requires a gateway API key:

  • OpenAI route: Authorization: Bearer <gateway key>
  • Anthropic route: x-api-key: <gateway key>, or a Bearer token. If you send both, they must have the same value.

Endpoints

EndpointProvider reference
GET /openai/v1/modelsList models
GET /anthropic/v1/modelsList models
POST /openai/v1/responsesCreate a response
POST /openai/v1/responses/compactCompact a response
POST /openai/v1/chat/completionsCreate a chat completion
POST /anthropic/v1/messagesCreate a message
POST /anthropic/v1/messages/count_tokensCount tokens

The models endpoints return the models your key can call, with IDs in the form <credential>:<model> (see model IDs). The gateway doesn't translate between formats, so the OpenAI endpoints need an OpenAI provider credential and the Anthropic endpoints an Anthropic credential.

Other paths return 404, including websockets and realtime APIs. Request bodies must be uncompressed: a Content-Encoding other than identity fails with 415.

Streaming usage

On streamed Chat Completions requests, the gateway sets stream_options.include_usage so that every call gets token usage and cost.

Your client receives a final chunk with an empty choices array and a usage object, just before data: [DONE]. Code that reads chunk.choices[0] on every chunk needs a guard.


Was this page helpful?

Last updated on