Full Example
Here’s a complete example showing how to use Pydantic AI with Lunary:- Agent calls and responses
- Model parameters and settings
- Output schema validation
- Performance metrics
- Errors and exceptions
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "https://api.lunary.ai" # replace by your api endpoint if you're self-hosting Lunary
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = f"Authorization=Bearer {os.environ['LUNARY_PRIVATE_KEY']}"
logfire.configure(send_to_logfire=False)
logfire.instrument_pydantic_ai()
import os
import logfire
from pydantic import BaseModel
from pydantic_ai import Agent
os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "https://api.lunary.ai"
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = f"Authorization=Bearer {os.environ['LUNARY_PRIVATE_KEY']}"
logfire.configure(send_to_logfire=False)
logfire.instrument_pydantic_ai()
class MyModel(BaseModel):
city: str
country: str
agent = Agent(model='open:gpt-4.1', output_type=MyModel, model_settings={'temperature': 0.7})
if __name__ == '__main__':
result = agent.run_sync('The windy city in the US of A.')
print(result.output)