Skip to navigation

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

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.

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.

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 for the full list.