Python Integration
Use ANT with the OpenAI SDK, Anthropic SDK, or raw HTTP requests.
OpenAI SDK (Recommended)
Install the SDK if you haven't already:
pip install openaiBasic Usage
from openai import OpenAI
client = OpenAI(
base_url="https://antbase.ai/v1",
api_key="sk-ant-your-api-key",
)
response = client.chat.completions.create(
model="ant:auto", # Let ANT pick the best model
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain quantum computing in simple terms."},
],
)
print(response.choices[0].message.content)Streaming
stream = client.chat.completions.create(
model="ant:auto",
messages=[{"role": "user", "content": "Write a short poem about coding."}],
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)Async
from openai import AsyncOpenAI
import asyncio
client = AsyncOpenAI(
base_url="https://antbase.ai/v1",
api_key="sk-ant-your-api-key",
)
async def main():
response = await client.chat.completions.create(
model="ant:best", # Use best quality for complex tasks
messages=[{"role": "user", "content": "Review this code for bugs..."}],
)
print(response.choices[0].message.content)
asyncio.run(main())Environment Variables
Both SDKs support reading from environment variables:
# .env or shell
export OPENAI_API_BASE=https://antbase.ai/v1
export OPENAI_API_KEY=sk-ant-your-api-key
# Then in Python (no need to pass base_url or api_key)
from openai import OpenAI
client = OpenAI() # Reads from environmentTips
- Use
ant:fastfor simple queries to minimize latency - Use
ant:bestfor code review, complex reasoning, or when quality matters most - Check the
X-Antbase-Modelresponse header to see which model was actually used - Implement retry logic for 5xx errors — ANT has automatic failover but upstream providers can still fail