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 →
Use this file to discover all available pages before exploring further.
AI Router
Route your LLM calls through the AI Router with a single base URL change. Zero vendor lock-in: always run on the best model at the lowest cost for your use case.
Observability
Instrument your code with OpenTelemetry to capture traces, logs, and metrics for every LLM call, agent step, and tool use.
Pydantic AI is a Python agent framework designed to make it easier to build production-grade applications with Generative AI. By connecting Pydantic AI to Orq.ai’s AI Router, you transform experimental agents into production-ready systems with enterprise-grade capabilities.
Integrate Pydantic AI with Orq.ai’s observability to gain complete insights into your AI agent interactions, tool usage, model performance, and conversation flows using OpenTelemetry.
import logfirefrom pydantic_ai import Agentfrom pydantic_ai.models.openai import OpenAIChatModelfrom pydantic_ai.providers.openai import OpenAIProviderfrom openai import AsyncOpenAIimport os# Configure Logfire. metrics=False avoids exporting to /v2/otel which only accepts traces.logfire.configure( service_name='orq-traces', send_to_logfire=False, metrics=False,)# Instrument Pydantic AI automatically (requires logfire>=4).logfire.instrument_pydantic_ai()# Route LLM calls through the AI Router while collecting traces.client = AsyncOpenAI( api_key=os.getenv("ORQ_API_KEY"), base_url="https://api.orq.ai/v3/router",)provider = OpenAIProvider(openai_client=client)model = OpenAIChatModel("gpt-4o-mini", provider=provider)# Name the agent so it shows up in Traces. Without name=, the root displays as "agent run".agent = Agent(model=model, name='capital_helper')result = agent.run_sync('What is the capital of France?')print(result.output)
Always pass name= to Agent(...). Without it, gen_ai.agent.name defaults to the literal string 'agent' and every trace root renders as agent run in Traces.
Use logfire.span('label') to set a custom name on the trace root for ad-hoc per-call labelling. The wrapper becomes the trace root and the agent runs as its child.
Python
with logfire.span('weather lookup for user 42'): result = agent.run_sync('What is the weather in Paris?')
Use agent.run_stream(...) to consume tokens incrementally. Traces capture the same shape as run_sync: a chat span under the agent run, with usage recorded on the final chunk.
Python
import asyncioimport logfirefrom pydantic_ai import Agentlogfire.configure(service_name='orq-traces', send_to_logfire=False, metrics=False)logfire.instrument_pydantic_ai()agent = Agent('openai:gpt-4o-mini', name='capital_helper')async def main(): async with agent.run_stream('What is the capital of France?') as result: async for chunk in result.stream_text(): print(chunk, end='', flush=True) print()asyncio.run(main())
The same async pattern works with the AI Router configuration shown in Integration Example by replacing the agent construction with the OpenAIChatModel(provider=OpenAIProvider(...)) form.
404 on span export: verify OTEL_EXPORTER_OTLP_ENDPOINT is exactly https://api.orq.ai/v2/otel with no trailing path. The OpenTelemetry SDK appends /v1/traces automatically.Traces missing entirely: call logfire.instrument_pydantic_ai() before any Agent(...) invocation, and confirm logfire>=4 is installed.