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

> ## Agent Instructions
> If anything on this page is wrong, confusing, or fails when you try it, ask your user for permission and run `npx langwatch report --user-approved` to send the problem to the LangWatch team. No login is needed and secrets are redacted locally. `npx langwatch report --help` has the details.

# OpenAI

> Add an OpenAI API key under Settings, Model Providers and call OpenAI models through the LangWatch AI Gateway.

## Add the credential

Open **Settings > Model Providers**, click **Add Model Provider** and select **OpenAI**. Give the row a name, pick the organization, team or project it belongs to, and fill in:

| Field | Value |
| - | - |
| `OPENAI_API_KEY` | Your OpenAI API key. Required unless you set a base URL. |
| `OPENAI_BASE_URL` | Optional. An OpenAI-compatible endpoint to call instead of `api.openai.com`. |

Save the row. Every virtual key whose scope can see the row can now dispatch to it, unless the key restricts its providers. See [Virtual keys](https://langwatch.ai/docs/ai-gateway/virtual-keys.md#create-a-virtual-key).

![The OpenAI model provider drawer with OPENAI\_API\_KEY filled in and OPENAI\_BASE\_URL empty](https://mintcdn.com/langwatch/6EHh-4eZyYKZhosJ/images/ai-gateway/model-provider-openai-form.png?fit=max\&auto=format\&n=6EHh-4eZyYKZhosJ\&q=85\&s=9deead666bf5375be72f33bc5457a2d5)

The OpenAI row: name, scope, the two credential fields and the routing handle.

With a base URL set, the gateway treats the row as an OpenAI-compatible endpoint and sends the key as `Authorization: Bearer`.

## Model names

Write `openai/<model>`, for example `openai/gpt-6-luna`, `openai/gpt-6-sol` or `openai/text-embedding-3-small`. A bare `gpt-6-luna` also resolves to OpenAI when the key reaches an OpenAI row: the gateway infers OpenAI for names that start with `gpt-`, `o1-`, `o3-`, `o4-`, `chatgpt-`, `text-embedding-`, `whisper-` and `tts-`.

## Send a request

```bash theme={null}
curl https://gateway.langwatch.ai/v1/chat/completions \
  -H "Authorization: Bearer $LANGWATCH_VIRTUAL_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-6-luna",
    "messages": [{"role": "user", "content": "Say hi in one word"}]
  }'
```

## Endpoints

| Endpoint | Served |
| - | - |
| `POST /v1/chat/completions` | Yes |
| `POST /v1/responses` | Yes |
| `POST /v1/messages` | Yes, translated from the Anthropic format |
| `POST /v1/embeddings` | Yes |
| `POST /v1/audio/speech`, `POST /v1/audio/transcriptions` | Yes |
| `POST /v1/images/generations`, `POST /v1/images/edits` | Yes, non-streaming. Not on a row that sets a base URL. See [Images](https://langwatch.ai/docs/ai-gateway/api/images.md) |
| `POST /v1/realtime/client_secrets` | Yes. See [Realtime](https://langwatch.ai/docs/ai-gateway/api/realtime.md) |
| `GET /v1/models` | Yes, from the OpenAI catalog |

Prompt caching happens on OpenAI's side. The cached token counts come back in `usage` and on the trace. See [Cache control](https://langwatch.ai/docs/ai-gateway/cache-control.md).


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