Skip to main content

PydanticAI Platform Client

A lightweight Python client for the PydanticAI Multi-Agent Platform API.

Installation

pip install pydanticai-platform-client

Or install from source:

pip install -e sdk/

Quick Start

from pydanticai_platform_client import PlatformClient

async def main():
    async with PlatformClient(
        base_url="https://your-platform.fly.dev",
        api_key="pk_your_tenant_key",
    ) as client:
        # Chat with the default agent
        response = await client.chat("What's the weather like?")
        print(response.text)

        # Use a specific agent
        response = await client.chat(
            "Analyze this data: [1, 2, 3, 4, 5]",
            agent="analyst",
        )
        print(response.text)

        # Continue a conversation
        response = await client.chat(
            "Tell me more",
            conversation_id=response.conversation_id,
        )

Streaming Responses

async with PlatformClient(base_url, api_key) as client:
    async for chunk in client.chat_stream("Write a poem about Python"):
        print(chunk, end="", flush=True)
    print()  # newline at the end

Available Methods

Method Description
chat(prompt, agent?, conversation_id?) Send a message, get complete response
chat_stream(prompt, agent?, conversation_id?) Stream response chunks
list_agents() List available agents
get_usage(days=30) Get usage statistics
list_conversations(limit=20) List recent conversations
get_conversation(id) Get full conversation history
clear_conversation(id) Delete a conversation

Error Handling

from pydanticai_platform_client import (
    PlatformClient,
    AuthenticationError,
    RateLimitError,
    TokenLimitError,
    AgentNotFoundError,
)

async with PlatformClient(base_url, api_key) as client:
    try:
        response = await client.chat("Hello")
    except AuthenticationError:
        print("Invalid API key")
    except RateLimitError as e:
        print(f"Rate limited, retry after {e.retry_after}s")
    except TokenLimitError as e:
        print(f"Token limit exceeded: {e.tokens_used}/{e.limit}")
    except AgentNotFoundError as e:
        print(f"Agent not found: {e.agent_name}")

Response Models

ChatResponse

@dataclass
class ChatResponse:
    text: str              # The agent's response
    conversation_id: str   # ID for continuing the conversation
    agent: str             # Agent that handled the request
    model: str             # Model used

UsageStats

@dataclass
class UsageStats:
    tenant_id: str
    period_days: int
    total_requests: int
    total_tokens: int
    estimated_cost_usd: float
    by_model: dict[str, int]
    by_agent: dict[str, int]

License

MIT

Release files for pydanticai-platform-client 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydanticai-platform-client 0.1.0
File Size Uploaded
pydanticai_platform_client-0.1.0.tar.gz 5.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydanticai-platform-client 0.1.0
File Interpreter ABI Platform
pydanticai_platform_client-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.0 kB

Release files / pydanticai_platform_client-0.1.0.tar.gz

Download URL pydanticai_platform_client-0.1.0.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7201ae3115d8a21d3d2229b705000c356e55060c1af037bc60386cdc753a13c7
BLAKE2b-256 checksum
How to use checksums
318c5356da233b1e7c7b1a507d998696a64320561e04c5dea8c6dca8d022d5dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.5

Release files / pydanticai_platform_client-0.1.0-py3-none-any.whl

Download URL pydanticai_platform_client-0.1.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2865f8153bce1edff581dc54b1b3ee91dccf7fe51b380606525b419463ce1540
BLAKE2b-256 checksum
How to use checksums
14202a8b03d3d0b13c63dc0097407e9bc2e79f300757d64115f89e9a6a33d80a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page