> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langdock.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Model Gateway quickstart

> Send your first request through the Langdock Model Gateway with curl, the OpenAI SDK or the Anthropic SDK.

The Model Gateway gives you every model enabled in your workspace behind one endpoint, `https://gateway.langdock.com`. It speaks the OpenAI Chat Completions, OpenAI Responses and Anthropic Messages formats, and any enabled model works with any of them. Your requests run under your Langdock account, count toward your spend limit, and show up in your usage.

> [!NOTE]
>
> The Model Gateway is rolling out. If **Create key** in your [account settings](https://docs.langdock.com/en/using-langdock/account/personal-api-keys.md) does not offer **Model Gateway key** yet, use the [classic endpoints](https://docs.langdock.com/en/developer/completion-api/completion-overview.md) on `api.langdock.com` with your personal API key instead.

## Before you start

* A **Model Gateway key**. Create one in [Settings > Account > API keys](https://docs.langdock.com/en/using-langdock/account/personal-api-keys.md) with **Create key > Model Gateway key**. If the page says what is missing, for example access or a spend limit, ask your workspace admin to fix that step.
* At least one model enabled for API use that you can access. **Available models** on the same page lists them with the model name to send.

Store the key in an environment variable so it stays out of your code:

```bash theme={null}
export LANGDOCK_API_KEY="sk-..."
```

## 1. List your models

```bash theme={null}
curl https://gateway.langdock.com/v1/models \
  -H "Authorization: Bearer $LANGDOCK_API_KEY"
```

The response is an OpenAI style list. Use an `id` from it as `model` in your requests. Each entry also lists the model's context window and the `operations` it supports.

## 2. Send a request

> [tab] curl
>
> ```bash theme={null}
> curl https://gateway.langdock.com/v1/chat/completions \
>   -H "Authorization: Bearer $LANGDOCK_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "model": "your-model-id",
>     "messages": [{ "role": "user", "content": "Explain AI in one sentence." }]
>   }'
> ```

> [tab] OpenAI SDK (Python)
>
> ```python theme={null}
> import os
> from openai import OpenAI
>
> client = OpenAI(
>     base_url="https://gateway.langdock.com/v1",
>     api_key=os.environ["LANGDOCK_API_KEY"],
> )
>
> response = client.chat.completions.create(
>     model="your-model-id",
>     messages=[{"role": "user", "content": "Explain AI in one sentence."}],
> )
> print(response.choices[0].message.content)
> ```

> [tab] OpenAI SDK (TypeScript)
>
> ```typescript theme={null}
> import OpenAI from "openai";
>
> const client = new OpenAI({
>   baseURL: "https://gateway.langdock.com/v1",
>   apiKey: process.env.LANGDOCK_API_KEY,
> });
>
> const response = await client.chat.completions.create({
>   model: "your-model-id",
>   messages: [{ role: "user", content: "Explain AI in one sentence." }],
> });
> console.log(response.choices[0].message.content);
> ```

> [tab] Anthropic SDK (Python)
>
> ```python theme={null}
> import os
> from anthropic import Anthropic
>
> client = Anthropic(
>     base_url="https://gateway.langdock.com",
>     api_key=os.environ["LANGDOCK_API_KEY"],
> )
>
> message = client.messages.create(
>     model="your-model-id",
>     max_tokens=256,
>     messages=[{"role": "user", "content": "Explain AI in one sentence."}],
> )
> print(message.content[0].text)
> ```

> [tab] Anthropic SDK (TypeScript)
>
> ```typescript theme={null}
> import Anthropic from "@anthropic-ai/sdk";
>
> const client = new Anthropic({
>   baseURL: "https://gateway.langdock.com",
>   apiKey: process.env.LANGDOCK_API_KEY,
> });
>
> const message = await client.messages.create({
>   model: "your-model-id",
>   max_tokens: 256,
>   messages: [{ role: "user", content: "Explain AI in one sentence." }],
> });
> console.log(message.content);
> ```

The OpenAI SDKs take the base URL with `/v1`. The Anthropic SDKs add `/v1/messages` themselves, so their base URL has no `/v1`. For the Responses API, call `client.responses.create(...)` on the same OpenAI client.

## 3. Check the cost

The final usage object of every response includes an estimated cost in US dollars:

```json theme={null}
"usage": {
  "prompt_tokens": 14,
  "completion_tokens": 21,
  "total_tokens": 35,
  "cost": 0.000357,
  "is_byok": false,
  "cost_details": { "currency": "USD", "estimate": true }
}
```

When you stream Chat Completions, set `"stream_options": { "include_usage": true }` to get the usage, and the cost, in the last chunk. Responses returns it in `response.completed` and Messages in `message_delta`. The cost is an estimate at list price. What you are billed is settled afterwards and shown in your [usage](https://docs.langdock.com/en/developer/model-gateway/limits-and-usage.md#see-your-usage). Requests on a premium tier and models without a list price have no `cost` field.

## Regions

| Region | OpenAI formats | Anthropic Messages |
| - | - | - |
| EU (default) | `https://gateway.langdock.com/v1` | `https://gateway.langdock.com` |
| US | `https://gateway.langdock.com/us/v1` | `https://gateway.langdock.com/us` |
| Global | `https://gateway.langdock.com/global/v1` | `https://gateway.langdock.com/global` |

If a model name exists in more than one region, either use the regional endpoint or the regional model name that `GET /v1/models` returns.

## Authentication

Send the key as `Authorization: Bearer <key>` or as `x-api-key: <key>`, not both. Call the gateway from a server, a script or a local tool, never from a web page, where anyone could read the key.

## What works where

| Request | Model Gateway key on `gateway.langdock.com` | Use instead |
| - | - | - |
| Chat Completions, Responses, Messages, model list | Yes | |
| Embeddings | Not yet (`403 model_gateway_unsupported`) | `https://api.langdock.com/openai/{region}/v1/embeddings` with the Embedding scope |
| Run an agent | No, agents are not a model endpoint | `https://api.langdock.com/agent/v1/chat/completions` with **Run agents** on your key |
| Workspace keys | Not yet (`403 model_gateway_unsupported`) | The classic endpoints on `api.langdock.com` |

## Next steps

> [card] [Connect coding tools](https://docs.langdock.com/en/developer/model-gateway/coding-tools.md)
>
> Claude Code, Codex, Cursor, GitHub Copilot, OpenCode and Claude Desktop

> [card] [Limits and usage](https://docs.langdock.com/en/developer/model-gateway/limits-and-usage.md)
>
> Spend limits, rate limits, cached tokens and where to see your usage

> [card] [Errors](https://docs.langdock.com/en/developer/model-gateway/errors.md)
>
> What each error means and how to fix it

> [card] [Which key do I need?](https://docs.langdock.com/en/developer/overview/api-keys.md)
>
> Model Gateway keys, Platform API keys, personal and workspace keys


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.