Pydantic AI
Pydantic AI is a Python agent framework from the Pydantic team, built around typed outputs. Bayle connects through its OpenAI provider and chat model.
Copies this page's setup instructions, to paste into your coding agent.
Show the prompt
Help me set this up to use Bayle AI, an OpenAI-compatible API. Full guide: https://docs.bayle.ai/guides/sdks/pydantic-ai/
Goal: build my Pydantic AI (https://pydantic.dev/docs/ai/overview/) agents on a Bayle model.
1. Install the package if `python -c "import pydantic_ai"` fails:
pip install "pydantic-ai-slim[openai]"
2. Pick a model. Typed outputs and tools rely on function calling, so choose one that supports it:
curl -s "https://api.bayle.ai/models?type=text" \
| jq -r '.data[] | select(.model_spec.capabilities.supportsFunctionCalling) | .id'
Show me the list, let me choose, and use that id as MODEL_ID.
3. In my code, build the model like this. Use OpenAIChatModel: the `openai:` model string resolves to the Responses model, which calls an API Bayle does not serve:
import os
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.openai import OpenAIProvider
model = OpenAIChatModel(
"MODEL_ID",
provider=OpenAIProvider(
base_url="https://api.bayle.ai",
api_key=os.environ["BAYLE_API_KEY"],
),
)
agent = Agent(model)
If I already have an Agent, change only the model it receives.
4. Verify by running:
print(agent.run_sync("In one sentence, what is an embedding?").output)
and show me the output.
Rules:
1. The base URL is https://api.bayle.ai exactly as written. Append no path to it.
2. Read the key from the BAYLE_API_KEY environment variable. Never write the key itself into a file you create, a command, a commit or the chat. Where the tool keeps the key in its own settings screen, tell me where to paste it. If BAYLE_API_KEY is not set, stop and ask me to create a key at https://chat.bayle.ai/developers and export it.
3. Take model ids only from GET https://api.bayle.ai/models (no key needed). Never guess one.
4. Finish with one real test request, show me the result and list the files you changed.Install
Section titled “Install”pip install "pydantic-ai-slim[openai]"See the official install guide for the other extras.
Don't have a Bayle key yet?Get API key
import osfrom pydantic_ai import Agentfrom pydantic_ai.models.openai import OpenAIChatModelfrom pydantic_ai.providers.openai import OpenAIProvider
model = OpenAIChatModel( "MODEL_ID", provider=OpenAIProvider( base_url="https://api.bayle.ai", api_key=os.environ["BAYLE_API_KEY"], ),)
agent = Agent(model)print(agent.run_sync("In one sentence, what is an embedding?").output)- Use
OpenAIChatModel. Theopenai:model string resolves to the Responses model, which calls an API Bayle doesn’t serve. - Typed outputs and tools rely on function calling, so pick a model that supports it.
Pick a model
Section titled “Pick a model”curl -s "https://api.bayle.ai/models?type=text" \ | jq -r '.data[] | select(.model_spec.capabilities.supportsFunctionCalling) | .id'