Python SDK
Install NanoGPT’s official Python SDK from PyPI. It needs Python 3.9 or later and has no runtime dependencies. The distribution is namednanogpt-python; the import package is nanogpt.
NANOGPT_API_KEY to your API key, then:
Streaming
Use thestream_ helpers for streaming; regular methods return one JSON response.
Async
AsyncNanoGPT exposes the same methods. Await regular calls and use async for with streaming helpers:
Errors and retries
API failures raiseNanoGPTError, with status-specific subclasses such as AuthenticationError and RateLimitError. Errors expose status, message, request_id, retry_after and response headers. Network failures use standard Python transport exceptions.
What it covers
The SDK supports Chat Completions, Responses, Anthropic Messages, embeddings, model listing, usage, account helpers and the file-backed Batch API. It includes file upload, batch quoting and creation, polling, results and cancellation. The separate Anthropic Message Batches API uses Anthropic’s official SDK. The default host ishttps://api.nano-gpt.com. Set base_url to use another host. For method details and Batch examples, see the SDK README on PyPI. For other endpoints, use the HTTP API.
For an OpenAI SDK integration, use base_url="https://api.nano-gpt.com/api/v1" with the official OpenAI client instead.