Docs
This guide covers llm-api-adapter==0.11.0. Start with the Quickstart to send a first message.
Installation
Use Python 3.10–3.14. Install Core in a virtual environment.
python -m pip install llm-api-adapter==0.11.0- Sync calls use
requestsby default. - For async calls, run
python -m pip install "llm-api-adapter[async]==0.11.0". - For sync HTTPX, run
python -m pip install "llm-api-adapter[httpx]==0.11.0"and passtransport="httpx".
Provider setup
Pass the provider ID as organization, the exact model ID as model, and a key from that provider as api_key. The examples read the key from the environment and pass it to the constructor.
For an optional provider such as Mistral, add its package alongside Core.
python -m pip install llm-api-adapter==0.11.0 llm-api-adapter-mistral==0.1.7| Provider and ID | Package in the catalog | Key in examples |
|---|---|---|
Anthropic anthropic | llm-api-adapter==0.11.0 | ANTHROPIC_API_KEY |
Google google | llm-api-adapter==0.11.0 | GOOGLE_API_KEY |
OpenAI openai | llm-api-adapter==0.11.0 | OPENAI_API_KEY |
DeepSeek deepseek | llm-api-adapter-deepseek==0.1.2 | DEEPSEEK_API_KEY |
Kimi kimi | llm-api-adapter-kimi==0.1.3 | KIMI_API_KEY |
Mistral mistral | llm-api-adapter-mistral==0.1.7 | MISTRAL_API_KEY |
Qwen qwen | llm-api-adapter-qwen==0.1.3 | QWEN_API_KEY |
xAI xai | llm-api-adapter-xai==0.1.5 | XAI_API_KEY |
Z.ai zai | llm-api-adapter-zai==0.1.3 | ZAI_API_KEY |
For Qwen, also pass the Frankfurt Global workspace_id to each chat or streaming call. Generate an installation command and Python snippet for a model in the interactive example.
Python API
Import UniversalLLMAPIAdapter from llm_api_adapter.universal_adapter. Use typed messages such as UserMessage from llm_api_adapter.models.messages.chat_message.
chat()returns aChatResponse. For async, useawait adapter.achat(...).stream_chat()yields text chunks for aforloop.astream_chat()is used withasync for.- Pass
toolsto get tool calls back for your application to execute. Usejson_schemaorresponse_modelfor supported structured output. - Use
max_tokensfor the output budget andtimeout_sfor the per-request timeout.
Try the sync example or seeasync and streaming examples andtool and schema examples.
Compatible endpoints
Both modes are installed with Core. Pass the server's exact model, a nonempty api_key, and an absolute HTTP(S) base_url including the version and any proxy prefix, such as http://localhost:8000/v1. The adapter appends the resource path.
organization="openai_compatible"uses/chat/completionsby default. Setapi_variant="responses"to use/responses.organization="anthropic_compatible"uses/messages. Leaveapi_variantunset and pass a positive integermax_tokenson every request.
Choose the protocol and send the full conversation history on each request. The adapter uses the selected protocol for every call. Check the server's documentation for supported features. Compatible connections use caller-supplied settings and tariffs, even when the model ID matches a native entry.
See connection examples for Chat Completions and Responses,Messages, andasync connections.
Limits
- Check the model catalog for context windows, output limits, and model-specific support for tools, files, reasoning, and structured output.
- Registered rules can omit unsupported sampling parameters. Supplying a value other than the default can produce a warning. See request compatibility.
- Usage depends on the counts reported by the provider. Calculated costs are estimates based on a known tariff and applicable usage. For a compatible connection, supply a caller tariff to calculate costs.
- Streaming completion callbacks require a successful end to the stream. Close a stream explicitly if you stop reading it early.
See usage and pricing examples and the catalog's source and date.