This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This project uses Poetry for dependency management and Invoke for task automation.
invoke test- Run unit testsinvoke test --coverage- Run unit tests with coverage reportpoetry run pytest- Run tests directly with Poetry
invoke lint- Run ruff linter (check only)invoke lint --fix- Run ruff linter with auto-fixinvoke formatter- Check code formatting with blackinvoke formatter --fix- Format code with blackinvoke staticcheck- Run mypy type checkinginvoke isort- Run import sorting
invoke build- Build the package with Poetrypoetry build- Direct Poetry build command
invoke update- Update all dependenciesinvoke outdated- Show outdated packagesinvoke audit- Run security audit with safety
This is the AI21 Labs Python SDK, a comprehensive client library for interacting with AI21's language models across multiple deployment platforms.
- Studio Client (
ai21.AI21Client): Primary client for AI21 Studio API - Bedrock Client (
ai21.AI21BedrockClient): AWS Bedrock integration - Azure Client (
ai21.AI21AzureClient): Azure AI Studio integration - Vertex Client (
ai21.AI21VertexClient): Google Cloud Vertex AI integration - Launchpad Client (
ai21.AI21LaunchpadClient): AI21 Launchpad platform
All clients support both synchronous and asynchronous operations with corresponding Async* variants.
- Chat Completions: Modern chat-based API with support for system/user/assistant roles
- Maestro: AI Planning & Orchestration System for enterprise workflows
- Conversational RAG: Chat with document retrieval from Studio library
- Streaming: Real-time response streaming for chat completions
- File Management: Upload and manage documents in Studio library
ai21/clients/- Platform-specific client implementationsai21/models/- Pydantic models for requests/responsesai21/http_client/- HTTP layer with retry logic and error handlingai21/stream/- Streaming response handlingai21/errors.py- Custom exception hierarchyexamples/- Usage examples for all platforms and features
Each client exposes resources through attributes:
client.chat.completions- Chat completion APIclient.beta.maestro.runs- Maestro orchestrationclient.library.files- File upload/managementclient.beta.conversational_rag- RAG functionality
The SDK uses AI21EnvConfig for environment-based configuration supporting:
AI21_API_KEY- AuthenticationAI21_API_HOST- Custom API endpointsAI21_TIMEOUT_SEC- Request timeoutsAI21_NUM_RETRIES- Retry configurationAI21_LOG_LEVEL- Logging verbosity
tests/unittests/- Unit tests with mockingtests/integration_tests/- Live API integration tests- Uses pytest with async support and mock fixtures