Python SDK
Use the anthropic or openai Python package with OneProvider by changing only base_url. Covers sync and async clients, streaming, tool use and retries.
Two Python paths — anthropic for native Claude code, openai for migrations. Both work with one base_url change.
All models, capabilities, and prices Documentation index for AI agents:https://oneprovider.dev/docs/llms.txt Operating system Before you start: a key from your cabinet Open your cabinet: the Telegram bot @oneprovider_robot (Account) or app.oneprovider.dev . Press “Issue a key”, give it a name (for example, this client) and a spend limit, and copy the key. You top up the balance in the same place. More about the cabinet and keys . Install
bashpip3 install anthropic
# or, for OpenAI-style code:
pip3 install openai
# In a venv (recommended):
# python3 -m venv .venv && source .venv/bin/activate
# pip install anthropic openai Anthropic SDK
pythonimport os
from anthropic import Anthropic
client = Anthropic(
api_key=os.environ["ONEPROVIDER_KEY"],
base_url="https://api.oneprovider.dev",
)
resp = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Say hi."}],
)
print(resp.content[0].text) OpenAI-compatible
pythonimport os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["ONEPROVIDER_KEY"],
base_url="https://api.oneprovider.dev/v1",
)
resp = client.chat.completions.create(
model="claude-sonnet-5-5",
messages=[{"role": "user", "content": "Say hi."}],
)
print(resp.choices[0].message.content) Async client
pythonimport asyncio
from anthropic import AsyncAnthropic
async def main():
client = AsyncAnthropic(base_url="https://api.oneprovider.dev")
resp = await client.messages.create(
model="claude-sonnet-5-5",
max_tokens=512,
messages=[{"role": "user", "content": "Hi async."}],
)
print(resp.content[0].text)
asyncio.run(main()) Streaming
pythonwith client.messages.stream(
model="claude-sonnet-5-5",
max_tokens=512,
messages=[{"role": "user", "content": "Tell me a haiku."}],
) as stream:
for chunk in stream.text_stream:
print(chunk, end="", flush=True) Tool use
pythontools = [{
"name": "get_weather",
"description": "Get current weather for a city.",
"input_schema": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
}]
resp = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=1024,
tools=tools,
messages=[{"role": "user", "content": "What's the weather in Frankfurt?"}],
)
# resp.stop_reason == "tool_use"
# Inspect resp.content for tool_use blocks. Retry & error handling
pythonfrom anthropic import APIStatusError
from tenacity import retry, stop_after_attempt, wait_exponential
@retry(
stop=stop_after_attempt(3),
wait=wait_exponential(multiplier=0.5, min=0.5, max=4),
retry_error_cls=APIStatusError,
)
def call():
return client.messages.create(
model="claude-sonnet-5-5",
max_tokens=512,
messages=[{"role": "user", "content": "Hi."}],
) Don't hardcode the key Always read the key from an environment variable or a secret manager. Hardcoded keys leak into version control sooner or later. Which model to choose
Pass the id in model. claude-sonnet-5-5 is the default for most code, claude-haiku-5-5 for fast, high-volume calls and claude-opus-5-5 for hard reasoning. The OpenAI-compatible form also accepts GPT ids such as gpt-5.6-terra. Use the Anthropic form with https://api.oneprovider.dev and the OpenAI form with https://api.oneprovider.dev/v1. Ids are on the models page .
Common errors and fixes
404 NotFoundError
Anthropic SDK: base_url="https://api.oneprovider.dev" with no /v1. OpenAI SDK: base_url="https://api.oneprovider.dev/v1" with /v1.
401 AuthenticationError
The environment variable is empty or has a trailing newline. Print len(os.environ["ONEPROVIDER_KEY"]) before the call.
429 RateLimitError
Check the message: “Insufficient balance” means top up (do not retry), any other 429 is a rate limit, so back off and respect Retry-After.
APIConnectionError or read timeout
Disable VPN or proxy variables (HTTPS_PROXY), and use streaming for long answers: a non-streaming request must start within 6 minutes.
400 about max_tokens
The Anthropic SDK requires max_tokens in every request.
FAQ
Can I keep the official SDKs?
Yes. Only the key and base_url change, see migrate from Anthropic and migrate from OpenAI .
Does streaming work?
Yes, with both SDKs; see Streaming .
Where do I keep the key?
In an environment variable, never in the repository.
Quick answers
Which base URL do I use?
Claude Code and Anthropic SDKs use https://api.oneprovider.dev. OpenAI SDKs and OpenAI-compatible clients use https://api.oneprovider.dev/v1. One key works behind both; the model list is on the models page ; rates are on the pricing page .
How do I authenticate?
Send the raw sk-… key in x-api-key or Authorization: Bearer: one of them, never both. Keep the key in an environment variable, not in a file that gets committed. More on authentication .
Where do I get a key?
Open your cabinet in the Telegram bot @oneprovider_robot or at app.oneprovider.dev, top up the balance and press “Issue a key”. Each key can carry its own spend limit. Cabinet & API keys .
What do 401, 404 and 429 mean?
401: the key is missing, mistyped or sent in the wrong header; paste the whole key without quotes or spaces. 404: usually a wrong base URL, for example a missing or doubled /v1. 429 with “Insufficient balance”: the cabinet balance or the key’s spend limit is used up, so top up instead of retrying; any other 429 is a rate limit, so wait for Retry-After. Details: error codes and troubleshooting .
Why do streams cut off or reset?
VPN and VLESS proxies often buffer SSE or break HTTP/2 negotiation. OneProvider has no regional restrictions and does not buffer streams, so turn the proxy off and retry.
Where do I ask if this is not enough?
Message @Oneproviderhelpbot on Telegram or open “Support” in the web cabinet, with the HTTP status code and the exact error message. How support works .
Last updated: 2026-10-05 Found a bug? @Oneproviderhelpbot