🔄 anth2oai
Anthropic to OpenAI API Wrapper
Use Anthropic's Claude models with OpenAI-compatible API interface
Overview
anth2oai is a lightweight wrapper that allows you to use Anthropic's Claude models through an OpenAI-compatible API interface. This makes it easy to switch between OpenAI and Anthropic models in your existing codebase with minimal changes.
Features
- ✅ OpenAI-compatible interface - Drop-in replacement for OpenAI client
- ✅ Async & Sync support - Both
AsyncAnth2OAIandAnth2OAIclients available - ✅ Streaming support - Full support for streaming responses
- ✅ Tool/Function calling - Automatic conversion of OpenAI tools format to Anthropic format
- ✅ System prompts - Automatic handling of system messages
- ✅ Custom base URL - Support for Anthropic API proxies
Installation
pip install anth2oai
Or install from source:
git clone https://github.com/your-repo/anth2oai.git
cd anth2oai
pip install -e .
Quick Start
Async Client
import asyncio
from anth2oai import AsyncAnth2OAI
async def main():
client = AsyncAnth2OAI(
api_key="your-anthropic-api-key",
# base_url="https://api.anthropic.com" # Optional: custom endpoint
)
# Non-streaming
response = await client.chat.completions.create(
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello, who are you?"}
],
model="claude-sonnet-4-5-20250929",
)
print(response.choices[0].message.content)
# Streaming
stream = await client.chat.completions.create(
messages=[{"role": "user", "content": "Tell me a joke"}],
model="claude-sonnet-4-5-20250929",
stream=True,
)
async for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
asyncio.run(main())
Sync Client
from anth2oai import Anth2OAI
client = Anth2OAI(
api_key="your-anthropic-api-key",
)
# Non-streaming
response = client.chat.completions.create(
messages=[{"role": "user", "content": "Hello!"}],
model="claude-sonnet-4-5-20250929",
)
print(response.choices[0].message.content)
# Streaming
for chunk in client.chat.completions.create(
messages=[{"role": "user", "content": "Count to 5"}],
model="claude-sonnet-4-5-20250929",
stream=True,
):
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
Tool/Function Calling
The wrapper automatically converts OpenAI's tool format to Anthropic's format:
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City name, e.g., San Francisco",
},
},
"required": ["location"],
},
},
},
]
response = await client.chat.completions.create(
messages=[{"role": "user", "content": "What's the weather in Tokyo?"}],
model="claude-sonnet-4-5-20250929",
tools=tools,
)
# Check for tool calls
if response.choices[0].message.tool_calls:
for tool_call in response.choices[0].message.tool_calls:
print(f"Function: {tool_call.function.name}")
print(f"Arguments: {tool_call.function.arguments}")
Configuration
Environment Variables
You can configure the client using environment variables:
export OPENAI_API_KEY="your-anthropic-api-key"
export OPENAI_BASE_URL="https://api.anthropic.com" # Optional
Then simply:
client = AsyncAnth2OAI() # Will use env variables
Available Parameters
| Parameter | Description | Default |
|---|---|---|
api_key |
Anthropic API key | OPENAI_API_KEY env var |
base_url |
API endpoint URL | https://api.anthropic.com |
max_tokens |
Maximum tokens in response | 1024 |
timeout |
Request timeout in seconds | None |
Response Format
Responses are returned in OpenAI's ChatCompletion format:
ChatCompletion(
id='chatcmpl-xxx',
choices=[
Choice(
finish_reason='stop',
index=0,
message=ChatCompletionMessage(
content='Hello! How can I help you today?',
role='assistant',
tool_calls=None,
),
)
],
created=1234567890,
model='claude-sonnet-4-5-20250929',
object='chat.completion',
usage=CompletionUsage(
completion_tokens=10,
prompt_tokens=5,
total_tokens=15,
),
)
Supported Models
Any Anthropic model can be used. Common models include:
claude-sonnet-4-5-20250929(Claude 3.5 Sonnet)claude-3-opus-20240229(Claude 3 Opus)claude-3-haiku-20240307(Claude 3 Haiku)
License
MIT License - see LICENSE for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgements
This project is inspired by the need to easily switch between OpenAI and Anthropic APIs in production applications.
Metadata
Release files for anth2oai 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| anth2oai-0.1.0.tar.gz | 8.8 kB | Without provenance | Details for anth2oai-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| anth2oai-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for anth2oai-0.1.0-py3-none-any.whl |
Total release size: 18.0 kB
Release files / anth2oai-0.1.0.tar.gz
| Download URL | anth2oai-0.1.0.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e2ce6f02ebc2811618947c4c5e2b10a4c7998528b757e96331bc83e2334d34bd
|
|
BLAKE2b-256 checksum How to use checksums |
ceaeae414b0322fa041324824563a3ab4a205686091c376b93a1f9e351246922
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / anth2oai-0.1.0-py3-none-any.whl
| Download URL | anth2oai-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
79dbdbe0026f16f5e010784dbb44d0dc23023064b73ffa157b4bcd076f6f98d1
|
|
BLAKE2b-256 checksum How to use checksums |
da49a42357f1f0b36104a00748d06ddf569e3fb967b2c0c34b7cc7c18d9fbed2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for anth2oai 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.