PydanticAI with Meridian
Drop-in OpenAI-compatible model provider for pydantic-ai. Structured outputs, tool-calling agents, and multi-step workflows all route through Meridian’s gateway.
Install
pip install pydantic-ai openaiConfigure
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIModel
model = OpenAIModel(
"gpt-4o", # or any Meridian-routed model
api_key="sk-meridian-...",
base_url="https://api.meridian.lock/v1",
)
agent = Agent(model, system_prompt="You are a precise assistant.")
result = agent.run_sync("Summarize the LOCK protocol.")
print(result.data)Structured Output
from pydantic import BaseModel
class Summary(BaseModel):
title: str
bullets: list[str]
agent = Agent(model, result_type=Summary)
result = agent.run_sync("Explain zero-knowledge proofs.")
print(result.data.title)Tool Calling
@agent.tool
def get_weather(city: str) -> str:
# Call your weather API here
return f"Weather in {city}: 72°F, clear"
result = agent.run_sync("What's the weather in Denver?")
print(result.data)Notes
base_urlmust include/v1— Meridian exposes the standard OpenAI-compatible path.- Model names are passed through to Meridian’s routing layer. Use any model alias configured in your LOCK dashboard.
- Streaming (
run_stream) and async (run) work identically — Meridian proxies the full OpenAI chat/completions contract. - API keys are scoped per workspace. Generate them under LOCK → API Keys.