> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.beatapi.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.beatapi.io/_mcp/server.

# What changes when I use BeatAPI with the OpenAI SDK?

> Using the OpenAI SDK with BeatAPI changes only the API key, base_url (https://direct.beatapi.io/v1), and exact model ID while keeping existing Chat Completions or Responses calls.

Connecting the OpenAI SDK to BeatAPI requires changing only three settings: the API key, `base_url` (`https://direct.beatapi.io/v1`), and the exact enabled `model` ID. Existing Chat Completions (`messages`) and Responses (`input`) code structures remain unchanged.

## Minimal SDK configuration

Configure the server-side SDK client with `BEATAPI_API_KEY`, point `base_url` to `https://direct.beatapi.io/v1` (which avoids Cloudflare's 100-second limit on long text calls; `https://api.beatapi.io/v1` serves as fallback), and choose an enabled model ID such as `gpt-6-luna`.

```python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["BEATAPI_API_KEY"],
    base_url="https://direct.beatapi.io/v1",
)

completion = client.chat.completions.create(
    model="gpt-6-luna",
    messages=[{"role": "user", "content": "Reply with OK."}],
)
print(completion.model, completion.choices[0].message.content)
```

## Verification and rollout steps

1. **Check enabled models**: Call `GET https://api.beatapi.io/v1/models` with `Authorization: Bearer <BEATAPI_API_KEY>` when unsure which model IDs the key can reach.
2. **Match protocol shape**: Keep `messages` for Chat Completions (`POST /v1/chat/completions`) and `input` for Responses (`POST /v1/responses`).
3. **Enable options incrementally**: After one short non-streaming request returns the expected `model` and content, turn streaming and structured output options back on one at a time. Keep permanent keys on trusted servers rather than client bundles.

[GPT reference](/api-reference/text-api/gpt-chat-completions)

## Contracts and related questions

Before sending a paid request, inspect the model contracts for free: `model:gpt-6-luna`, `model:gpt-image-2.5-flare-std`.

[Back to AI Models questions](/faq/models).