# Connect Pydantic AI to aicharged.io

> Pydantic AI: an MCPToolset with the API key as auth, added to the agent toolsets.

## At a glance

| Kind | Sign-in | Platforms | Status | Verified |
|---|---|---|---|---|
| SDKs & frameworks | API key (Bearer), OAuth sign-in | macOS, Linux, Windows | works today | 2026-10-22 |

- MCP: `https://aicharged.io/api/v1/mcp`
- Docs: https://pydantic.dev/docs/ai/mcp/client

## Recipe

Agent code:

```python
import asyncio, os
from pydantic_ai import Agent
from pydantic_ai.mcp import MCPToolset

toolset = MCPToolset("https://aicharged.io/api/v1/mcp", auth=os.environ["AICHARGED_API_KEY"])
agent = Agent("openai:gpt-6.1-sol", toolsets=[toolset])

async def main():
    result = await agent.run("List my recent aicharged.io runs")
    print(result.output)

asyncio.run(main())
```

Install the package:

```sh
pip install pydantic-ai
```

[Client documentation](https://pydantic.dev/docs/ai/mcp/client)

## Authentication

- Send `Authorization: Bearer <API_KEY>` with every request. Create a key at https://aicharged.io/admin/account/api-keys.
- OAuth 2.1 (PKCE S256) is available for clients that cannot send a static key (ChatGPT).
- Without a key the endpoint answers 401 with a WWW-Authenticate header that points to https://aicharged.io/.well-known/oauth-protected-resource.

All 51 clients: https://aicharged.io/connect.md

HTML version: https://aicharged.io/connect/pydantic-ai
