Use Pydantic AI with Shannon
Give Pydantic AI an OpenAIChatModel with an OpenAIProvider pointed at Shannon; agents, tools and streaming then run on Shannon models.
- Tested Nov 7, 2026
- OpenAI Chat Completions
- About 2 min
About Pydantic AI
Pydantic AI is a Python framework for agents with typed inputs, tools and outputs, from the team behind Pydantic. It validates what the model returns and retries on bad output. Its OpenAI provider takes a base URL, so agents can run on Shannon models with tool calls and streaming.
What you need
- A Shannon API key
- Keys & usage
- Base URL
-
https://api.shannon-ai.com/v1Endpoint:/v1/chat/completions - Every snippet below follows your choice.
Set it up
-
Install Pydantic AI with the OpenAI extra
Shellpip install 'pydantic-ai-slim[openai]' -
Create the model and an agent
Pythonfrom pydantic_ai import Agent from pydantic_ai.models.openai import OpenAIChatModel from pydantic_ai.providers.openai import OpenAIProvider model = OpenAIChatModel( "Kimi-K3-uncensored-NVFP4", provider=OpenAIProvider(base_url="https://api.shannon-ai.com/v1", api_key="YOUR_API_KEY"), ) agent = Agent(model) @agent.tool_plain def get_weather(city: str) -> str: """Weather for a city.""" return f"Sunny, 18 C in {city}" print(agent.run_sync("What is the weather in Oslo?").output) -
Stream text
Pythonimport asyncio async def main(): async with agent.run_stream("Name three colours a cat can be.") as result: async for text in result.stream_text(delta=True): print(text, end="", flush=True) asyncio.run(main())
Check that it works
Send: Run the agent sample.
You should see: The agent calls get_weather and answers with the sunny weather in Oslo.
Models that fit Pydantic AI
Every id below meets what Pydantic AI needs. The first one is the default in the snippets.
| Model id | Context window | Max output | Image input |
|---|---|---|---|
Kimi-K3-uncensored-NVFP4 | 1,022,976 | 262,144 | Yes |
Kimi-K3-uncensored-3BIT-REAP | 225,280 | 225,280 | Yes |
shannon-3 | 196,608 | 65,536 | Yes |
shannon-coder-1 | 131,072 | 65,536 | No |
Good to know
- Use
OpenAIChatModelfor Shannon's Chat Completions endpoint;OpenAIResponsesModeluses/v1/responses, which Shannon also serves without storing replies. - A tool call costs two requests: one that asks for the tool, one that writes the answer from its result.
Tips
output_type=with a Pydantic model makes the agent return validated, typed data.OpenAIProvideralso readsOPENAI_BASE_URLandOPENAI_API_KEYfrom the environment.agent.run_syncis the simplest call in scripts;run_streamstreams text in async code.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
404 Not Found | base_url lacks /v1. | Use https://api.shannon-ai.com/v1. |
ModuleNotFoundError: openai | The slim package was installed without the OpenAI extra. | Install pydantic-ai-slim[openai]. |
401 Unauthorized | The key is missing, mistyped or rotated. | Copy the key again from Keys & usage; it starts with sk-. |
context_length_exceeded / "prompt is too long" | The conversation is longer than the model's window. | Start a new chat, let the tool compact it, or pick a model with a larger window. |
insufficient_quota | Your balance cannot pay for the request. | Top up or change plan; the request is not retried by itself. |
Questions
Does Pydantic AI work with Shannon?
Yes, through OpenAIChatModel and OpenAIProvider(base_url="https://api.shannon-ai.com/v1").
Do typed outputs work?
Yes; Pydantic AI gets them through tool calls, which Shannon models make.