Pydantic AI
Build Pydantic AI agents with Cortecs
Pydantic AI can use a custom OpenAI-compatible provider. Its Responses model is the preferred option for new Cortecs agents.
1. Install Pydantic AI
pip install "pydantic-ai-slim[openai]"2. Configure a Responses model
import os
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIResponsesModel
from pydantic_ai.providers.openai import OpenAIProvider
provider = OpenAIProvider(
base_url="https://api.cortecs.ai/v1",
api_key=os.environ["CORTECS_API_KEY"],
)
model = OpenAIResponsesModel(
os.environ["CORTECS_MODEL"],
provider=provider,
)
agent = Agent(
model,
instructions="Answer with a short, practical explanation.",
)
result = agent.run_sync("How does provider routing improve reliability?")
print(result.output)Choose a model that lists tools in supported_features before adding Pydantic AI tools. Cortecs does not currently document OpenAI-managed conversation storage, so avoid Pydantic AI features that depend on that service.
Chat Completions fallback
If a Pydantic AI feature or model requires Chat Completions, change only the model class:
Both configurations use the same Cortecs base URL and API key. See API Compatibility for endpoint differences and Advanced Usage for routing controls.
See the current Pydantic AI OpenAI model documentation for framework-specific options. Use only options that also appear in the Cortecs API reference.
Last updated