Skip to content
Pydantic AI

Frameworks and SDKs

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/v1 Endpoint: /v1/chat/completions
Every snippet below follows your choice.

Set it up

  1. Install Pydantic AI with the OpenAI extra

    Shell
    pip install 'pydantic-ai-slim[openai]'
  2. Create the model and an agent

    Python
    from 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)
  3. Stream text

    Python
    import 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 idContext windowMax outputImage 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 OpenAIChatModel for Shannon's Chat Completions endpoint; OpenAIResponsesModel uses /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

  1. output_type= with a Pydantic model makes the agent return validated, typed data.
  2. OpenAIProvider also reads OPENAI_BASE_URL and OPENAI_API_KEY from the environment.
  3. agent.run_sync is the simplest call in scripts; run_stream streams text in async code.

Troubleshooting

SymptomCauseFix
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.

Choose your language

All languages are equal. Pick the one you want to browse in.

Europe

Middle East & North Africa

South Asia

Southeast Asia

East Asia

Central Asia & Caucasus

Africa

Oceania

Constructed & Classical