For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DiscordPlatform
DocumentationIntegrationsAPI referenceSDKsChangelog
DocumentationIntegrationsAPI referenceSDKsChangelog
    • Overview
  • Tracing
  • Gateway
      • OpenAI Agents
      • Claude Agent SDK
      • Vercel AI SDK
      • Pydantic AI
      • CrewAI
      • Haystack
      • LangChain
      • LangGraph
      • Langflow
      • LlamaIndex
      • AutoGen
      • DSPy
      • Google ADK
      • Smolagents
      • Strands Agents
      • AgentSpec
      • Guardrails
      • Agno
      • MCP
      • BeeAI
      • Pipecat
      • Superagent
  • Others
  • Migrating
    • Braintrust
    • Portkey
    • Langfuse
LogoLogo
DiscordPlatform
On this page
  • Setup
  • Switch models
GatewayAgent Frameworks

DSPy (gateway)

Was this page helpful?
Previous

Google ADK (gateway)

Next
Built with

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

Setup

1

Install packages

$pip install respan-ai respan-instrumentation-dspy dspy
2

Set environment variables

$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
$export RESPAN_BASE_URL="https://api.respan.ai/api"

No OPENAI_API_KEY needed — the Respan gateway handles provider authentication.

3

Point DSPy to the Respan gateway

1import os
2import dspy
3
4lm = dspy.LM(
5 "openai/gpt-4o-mini",
6 api_key=os.environ["RESPAN_API_KEY"],
7 api_base=os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api"),
8 cache=False,
9)
10dspy.configure(lm=lm)
11
12class QA(dspy.Signature):
13 question: str = dspy.InputField()
14 answer: str = dspy.OutputField()
15
16result = dspy.ChainOfThought(QA)(question="What is the capital of France?")
17print(result.answer)

Switch models

DSPy uses LiteLLM-style model strings. Keep the openai/ provider prefix when calling the OpenAI-compatible Respan gateway, then change the model id to route to another provider through the same gateway.

1import os
2import dspy
3
4gateway_kwargs = {
5 "api_key": os.environ["RESPAN_API_KEY"],
6 "api_base": os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api"),
7 "cache": False,
8}
9
10dspy.configure(lm=dspy.LM("openai/gpt-4o-mini", **gateway_kwargs))
11dspy.configure(lm=dspy.LM("openai/claude-sonnet-4-5-20250929", **gateway_kwargs))
12dspy.configure(lm=dspy.LM("openai/gemini-2.5-flash", **gateway_kwargs))

See the full model list.