DSPy

Trace DSPy programs and optimizers with Respan.
  1. Sign up — Create an account at platform.respan.ai
  2. Create an API key — Generate one on the API keys page
  3. Add credits or a provider key — Add credits on the Credits page or connect your own provider key on the Integrations page

Add the Docs MCP to your AI coding tool to get help building with Respan. No API key needed.

1{
2 "mcpServers": {
3 "respan-docs": {
4 "url": "https://docs.respan.ai/mcp"
5 }
6 }
7}

What is DSPy?

DSPy is a framework from Stanford NLP for programming — not prompting — language models. It provides composable modules and automatic prompt optimization, replacing hand-crafted prompts with learnable programs.

Setup

1

Install packages

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

Set environment variables

$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
$export OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
3

Initialize and run

1import os
2from dotenv import load_dotenv
3
4load_dotenv()
5
6from respan import Respan
7from respan_instrumentation_openinference import OpenInferenceInstrumentor
8from openinference_instrumentation_dspy import DSPyInstrumentor
9import dspy
10
11# Initialize Respan with DSPy instrumentation
12respan = Respan(
13 instrumentations=[
14 OpenInferenceInstrumentor(instrumentor=DSPyInstrumentor())
15 ]
16)
17
18# Configure the language model
19lm = dspy.LM("openai/gpt-4o-mini")
20dspy.configure(lm=lm)
21
22# Define a signature
23class QA(dspy.Signature):
24 """Answer the question with a short, factual response."""
25 question: str = dspy.InputField()
26 answer: str = dspy.OutputField()
27
28# Create and run a module
29predict = dspy.ChainOfThought(QA)
30result = predict(question="What is the capital of France?")
31print(result.answer)
32
33respan.flush()
4

View your trace

Open the Traces page to see your DSPy program with module forward passes, chain-of-thought steps, and LLM calls.

What gets traced

All DSPy operations are auto-instrumented:

  • Module forward passes
  • LLM calls with model, tokens, and input/output
  • Optimizer steps and prompt mutations
  • Retrieval operations
  • Chain-of-thought reasoning steps

Traces appear in the Traces dashboard.

Learn more