---
title: "OpenAI SDK (gateway)"
description: "Set up OpenAI SDK with the Respan gateway."
---

Route OpenAI SDK calls through the Respan gateway to use 1000+ models from different providers. Only your `RESPAN_API_KEY` is needed. No separate provider keys are required.

Paste this into your coding agent:

```text
Help me set up the Respan gateway with the OpenAI SDK integration.
Follow https://www.respan.ai/docs/integrations/gateway/open-ai-sdk.md
```

## Setup

<Steps>
<Step title="Install packages">

<Tabs>
<Tab title={"Python"}>

```bash
pip install openai
```

</Tab>
<Tab title={"TypeScript"}>

```bash
npm install openai
```

</Tab>
</Tabs>

</Step>

<Step title="Set environment variables">

```bash
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
```

No `OPENAI_API_KEY` needed: the Respan gateway handles provider authentication.

</Step>

<Step title="Point the OpenAI client to the Respan gateway">

<Tabs>
<Tab title={"Python"}>

```python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("RESPAN_API_KEY"),
    base_url="https://gateway.respan.ai",
)

response = client.chat.completions.create(
    model="gpt-5.5",
    messages=[{"role": "user", "content": "Say hello in three languages."}],
)
print(response.choices[0].message.content)
```

</Tab>
<Tab title={"TypeScript"}>

```typescript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.RESPAN_API_KEY,
  baseURL: "https://gateway.respan.ai",
});

const response = await client.chat.completions.create({
  model: "gpt-5.5",
  messages: [{ role: "user", content: "Say hello in three languages." }],
});
console.log(response.choices[0].message.content);
```

</Tab>
</Tabs>

</Step>
</Steps>

## Switch models

Change the `model` parameter to use 1000+ models from different providers through the same gateway.

```python
response = client.chat.completions.create(model="gpt-5.5", messages=messages)
response = client.chat.completions.create(model="claude-sonnet-4-5-20250929", messages=messages)
response = client.chat.completions.create(model="gemini/gemini-3.5-flash", messages=messages)
```

See the [full model list](https://platform.respan.ai/platform/models).

## Prompt management

Use [Respan prompt management](/docs/documentation/features/prompt-management/prompt-management-quickstart) to serve prompt templates from the platform. Use `schema_version: 2` for all new integrations.

### Chat Completions

Prompt messages are the base layer (system/context). Body `messages` are appended as runtime user turns.

```python
PROMPT_ID = "YOUR_PROMPT_ID"

response = client.chat.completions.create(
    model="gpt-5.5",
    messages=[
        {"role": "user", "content": "Add dark mode support to the dashboard"},
    ],
    extra_body={
        "prompt": {
            "prompt_id": PROMPT_ID,
            "schema_version": 2,
            "variables": {
                "feature_request": "Add dark mode support",
            },
        }
    },
)
print(response.choices[0].message.content)
```

### Responses API

To send a Responses request to one provider, put its prefix in front of the model ID, such as `azure/gpt-5.5`.

For the Responses API, pass prompt config under `respan_params`. The prompt template becomes `instructions` and body `input` is preserved.

```python
PROMPT_ID = "YOUR_PROMPT_ID"

response = client.responses.create(
    model="gpt-5.5",
    input=[
        {"role": "user", "content": "Add dark mode support to the dashboard"},
    ],
    extra_body={
        "respan_params": {
            "prompt": {
                "prompt_id": PROMPT_ID,
                "schema_version": 2,
                "variables": {
                    "feature_request": "Add dark mode support",
                },
                "patch": {"top_p": None},
            }
        }
    },
)
print(response.output_text)
```

The `patch` drops the prompt's stored `top_p`. Reasoning models reject `top_p` on the Responses API, so leave the patch in place unless your prompt version was saved without it.

## Respan parameters

Pass additional Respan parameters via `extra_body` for gateway features.

```python
response = client.chat.completions.create(
    model="gpt-5.5",
    messages=[{"role": "user", "content": "Hello"}],
    extra_body={
        "customer_identifier": "user_123",
        "session_identifier": "conversation_456",
        "metadata": {"feature": "chat"},
    },
)
```

See [Respan params & metadata](/docs/ai-gateway/customers/respan-params) for the full list.
