Orq MCP is live: Use natural language to interrogate traces, spot regressions, and experiment your way to optimal AI configurations. Available in Claude Desktop, Claude Code, Cursor, and more. Start now →
Integrate DSPy with the AI Gateway for optimized LLM programs. Use Stanford’s framework for automatic prompt optimization and reasoning-based AI systems.
DSPy is a framework for programmatically optimizing LLM prompts and weights through composable modules and signatures. Connecting DSPy to Orq.ai’s AI Gateway provides access to 300+ models for prompt optimization pipelines with a single configuration change.
DSPy uses LiteLLM internally, which automatically prepends openai/ to the model name when routing to a custom api_base. Since the AI Gateway also requires the openai/ provider prefix, the model name must be double-prefixed so the final identifier reaching the gateway is correct: gpt-4o → openai/openai/gpt-4o.
import dspyimport oslm = dspy.LM( "openai/openai/gpt-4o", api_key=os.getenv("ORQ_API_KEY"), api_base="https://api.orq.ai/v3/router",)dspy.configure(lm=lm)class MathProblem(dspy.Signature): """Solve math problems step by step.""" problem: str = dspy.InputField() answer: str = dspy.OutputField()cot = dspy.ChainOfThought(MathProblem)result = cot(problem="If a train travels 120 miles in 2 hours, what is its speed?")print(result.answer)