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

# AgentSpec (gateway)

> Set up AgentSpec with the Respan gateway.

Route AgentSpec's underlying LLM calls through the Respan gateway to use 1000+ models from different providers. Only your `RESPAN_API_KEY` is needed — no separate provider keys required.

## Setup

#### Install packages

```bash
pip install "pyagentspec[langgraph]"
```

#### Set environment variables

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

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

#### Point AgentSpec to the Respan gateway

```python
import os
from pyagentspec.adapters.langgraph import AgentSpecLoader
from pyagentspec.agent import Agent
from pyagentspec.llms import OpenAiConfig

os.environ["OPENAI_API_KEY"] = os.environ["RESPAN_API_KEY"]
os.environ["OPENAI_BASE_URL"] = os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api")

agent = Agent(
    name="haiku_assistant",
    description="A helpful assistant that writes haikus.",
    llm_config=OpenAiConfig(name="openai", model_id="gpt-5.5"),
    system_prompt="You are a helpful assistant. Respond only with a haiku.",
)

langgraph_agent = AgentSpecLoader().load_component(agent)
result = langgraph_agent.invoke(
    input={"messages": [{"role": "user", "content": "Write a haiku about recursion."}]}
)
print(result["messages"][-1].content)
```

## Switch models

Change the `model_id` parameter on `OpenAiConfig` to use another OpenAI model through the same gateway-backed configuration.

```python
llm_config = OpenAiConfig(name="openai", model_id="gpt-5.5")
```

> **Note**
>
> AgentSpec's `OpenAiConfig(name="openai", ...)` is provider-specific configuration. This page avoids showing Claude or Gemini under that provider name; use the Respan API or OpenAI SDK gateway pages for provider-neutral Claude and Gemini examples.

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