OpenRouter (tracing)
OpenRouter is OpenAI-compatible. Use respan-instrumentation-openrouter to trace OpenRouter API calls from the OpenAI client and normalize them into OpenRouter-aware Respan spans.
Set up Respan
Create an account at platform.respan.ai and grab an API key .
Paste this into your coding agent:
Help me set up Respan tracing with the OpenRouter integration.
Follow https://www.respan.ai/docs/integrations/openrouter-tracing.mdSetup
Install packages
pip install respan-ai respan-instrumentation-openrouter openaiSet environment variables
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
export OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY"Initialize and run
import os
from openai import OpenAI
from respan import Respan
from respan_instrumentation_openrouter import OpenRouterInstrumentor
respan = Respan(
api_key=os.environ["RESPAN_API_KEY"],
app_name="openrouter-tracing",
instrumentations=[OpenRouterInstrumentor()],
)
client = OpenAI(
api_key=os.environ["OPENROUTER_API_KEY"],
base_url=os.getenv("OPENROUTER_BASE_URL", "https://openrouter.ai/api/v1"),
)
response = client.chat.completions.create(
model=os.getenv("OPENROUTER_MODEL", "openai/gpt-4o-mini"),
messages=[
{"role": "user", "content": "Summarize tracing with one sentence."}
],
)
print(response.choices[0].message.content)
respan.shutdown()View your trace
Open the Traces page to inspect normalized OpenRouter spans.
Gateway
For LLM routing through Respan, use the OpenRouter gateway page .