> 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.

# AgentScope (gateway)

> Set up AgentScope with the Respan gateway.

Route AgentScope OpenAI-compatible model calls through the Respan gateway to use models and provider credentials configured in Respan. Only your `RESPAN_API_KEY` is needed in the application.

## Setup

#### Install packages

```bash
pip install agentscope openai
```

#### Set environment variables

```bash
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
export RESPAN_BASE_URL="https://api.respan.ai/api"
export RESPAN_MODEL="gpt-5-mini"
```

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

#### Point AgentScope to the Respan gateway

```python
import asyncio
import os

from agentscope.agent import Agent
from agentscope.credential import OpenAICredential
from agentscope.message import UserMsg
from agentscope.model import OpenAIChatModel

credential = OpenAICredential(
    api_key=os.environ["RESPAN_API_KEY"],
    base_url=os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api"),
)
model = OpenAIChatModel(
    credential=credential,
    model=os.getenv("RESPAN_MODEL", "gpt-5-mini"),
    stream=False,
)
agent = Agent(
    name="assistant",
    system_prompt="Answer in one concise sentence.",
    model=model,
)

async def main() -> None:
    result = await agent.reply(
        UserMsg(name="user", content="Say hello through the Respan gateway."),
    )
    print(result.get_text_content())

asyncio.run(main())
```

## Switch models

Change `RESPAN_MODEL` to another model available in your Respan account.

```bash
export RESPAN_MODEL="gpt-5.5"
export RESPAN_MODEL="gpt-5-mini"
```

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

## Respan parameters

AgentScope forwards `extra_body` to OpenAI-compatible APIs, so you can pass Respan gateway parameters with the model configuration.

```python
model = OpenAIChatModel(
    credential=credential,
    model="gpt-5-mini",
    stream=False,
    extra_body={
        "customer_identifier": "user_123",
        "metadata": {"session_id": "abc123"},
        "thread_identifier": "conversation_456",
    },
)
```

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