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

Route Instructor's underlying OpenAI-compatible LLM calls through the Respan gateway to use 1000+ models from different providers. Only your Respan API key is needed - no separate provider key is required.

Paste this into your coding agent:

```text
Help me set up the Respan gateway with the Instructor integration.
Follow https://www.respan.ai/docs/integrations/gateway/instructor.md
```

## Setup

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

```bash
pip install instructor openai
```

</Step>

<Step title="Set environment variables">

```bash
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
export RESPAN_BASE_URL="https://gateway.respan.ai"
```

No `OPENAI_API_KEY` is needed when the request is routed through the Respan gateway.

</Step>

<Step title="Point Instructor to the Respan gateway">

```python
import os
from typing import TypedDict

import instructor

client = instructor.from_provider(
    "openai/gpt-5-mini",
    api_key=os.environ["RESPAN_API_KEY"],
    base_url=os.getenv("RESPAN_BASE_URL", "https://gateway.respan.ai"),
    mode=instructor.Mode.TOOLS,
)


class Person(TypedDict):
    name: str
    role: str


person = client.create(
    response_model=Person,
    messages=[
        {
            "role": "user",
            "content": "Grace Hopper was a pioneering computer scientist.",
        }
    ],
)
print(dict(person))
```

</Step>
</Steps>

## Switch models

Change the model string passed to `instructor.from_provider` to use another OpenAI model through the same gateway endpoint.

```python
client = instructor.from_provider(
    "openai/gpt-5.5",
    api_key=os.environ["RESPAN_API_KEY"],
    base_url=os.getenv("RESPAN_BASE_URL", "https://gateway.respan.ai"),
    mode=instructor.Mode.TOOLS,
)
```

<Note>
Instructor's `from_provider` string includes the SDK provider namespace. Keep this page to OpenAI models so Claude or Gemini are not shown as OpenAI-provider models. Use the Respan API or OpenAI SDK gateway pages for provider-neutral Claude and Gemini examples.
</Note>

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