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
| Route | Base URL |
|---|---|
| OpenAI | https://gateway.cloud.langfuse.com/openai/v1 |
| Anthropic | https://gateway.cloud.langfuse.com/anthropic/v1 |
These are the EU URLs. For other regions, replace the host with your gateway host.
Gateway hosts
| Region | Gateway host |
|---|---|
| EU | https://gateway.cloud.langfuse.com |
| US | https://gateway.us.cloud.langfuse.com |
| JP | https://gateway.jp.cloud.langfuse.com |
| HIPAA | https://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
| Endpoint | Provider reference |
|---|---|
GET /openai/v1/models | List models |
GET /anthropic/v1/models | List models |
POST /openai/v1/responses | Create a response |
POST /openai/v1/responses/compact | Compact a response |
POST /openai/v1/chat/completions | Create a chat completion |
POST /anthropic/v1/messages | Create a message |
POST /anthropic/v1/messages/count_tokens | Count 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.
Last updated on