Skip to main content

Python SDK

The official Perf SDK for Python provides both synchronous and asynchronous clients with Pydantic models, streaming support, and comprehensive error handling.

Installation

Quick Start

Configuration

Synchronous Client

Basic Request

With Cost Control

Request Options

Async Client

For async applications, use AsyncPerfClient:

Context Manager

Streaming

Synchronous Streaming

Async Streaming

Error Handling

The SDK provides typed exceptions for different error scenarios:

Exception Properties

All PerfError exceptions have these properties:

Rate Limit Error

Type Hints

The SDK uses Pydantic models with full type hints:

Response Types

ChatResponse

StreamChunk

Examples

Multi-turn Conversation

JSON Output

FastAPI Integration

Retry with Backoff

Requirements

  • Python 3.9 or higher
  • Dependencies: httpx, pydantic

Support