AgentScope (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

1

Install packages

$pip install agentscope openai
2

Set environment variables

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

3

Point AgentScope to the Respan gateway

1import asyncio
2import os
3
4from agentscope.agent import Agent
5from agentscope.credential import OpenAICredential
6from agentscope.message import UserMsg
7from agentscope.model import OpenAIChatModel
8
9credential = OpenAICredential(
10 api_key=os.environ["RESPAN_API_KEY"],
11 base_url=os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api"),
12)
13model = OpenAIChatModel(
14 credential=credential,
15 model=os.getenv("RESPAN_MODEL", "gpt-5-mini"),
16 stream=False,
17)
18agent = Agent(
19 name="assistant",
20 system_prompt="Answer in one concise sentence.",
21 model=model,
22)
23
24async def main() -> None:
25 result = await agent.reply(
26 UserMsg(name="user", content="Say hello through the Respan gateway."),
27 )
28 print(result.get_text_content())
29
30asyncio.run(main())

Switch models

Change RESPAN_MODEL to another model available in your Respan account.

$export RESPAN_MODEL="gpt-5.5"
$export RESPAN_MODEL="gpt-5-mini"

See the full model list.

Respan parameters

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

1model = OpenAIChatModel(
2 credential=credential,
3 model="gpt-5-mini",
4 stream=False,
5 extra_body={
6 "customer_identifier": "user_123",
7 "metadata": {"session_id": "abc123"},
8 "thread_identifier": "conversation_456",
9 },
10)

See Respan params & metadata for the full list.