Client
Instantiation
from airia import AiriaClient
# API Key Authentication
client = AiriaClient(
base_url="https://api.airia.ai", # Default: "https://api.airia.ai"
api_key=None, # Or set AIRIA_API_KEY environment variable
timeout=30.0, # Request timeout in seconds (default: 30.0)
log_requests=False, # Enable request/response logging (default: False)
custom_logger=None # Use custom logger (default: None - uses built-in)
)
# Bearer Token Authentication
client = AiriaClient(
base_url="https://api.airia.ai", # Default: "https://api.airia.ai"
bearer_token="your_bearer_token", # Must be provided explicitly (no env var fallback)
timeout=30.0, # Request timeout in seconds (default: 30.0)
log_requests=False, # Enable request/response logging (default: False)
custom_logger=None # Use custom logger (default: None - uses built-in)
)
# Convenience method for bearer token
client = AiriaClient.with_bearer_token(
bearer_token="your_bearer_token",
base_url="https://api.airia.ai", # Optional, uses default if not provided
timeout=30.0, # Optional, uses default if not provided
log_requests=False, # Optional, uses default if not provided
custom_logger=None # Optional, uses default if not provided
)
Authentication Methods
Airia supports two authentication methods:
API Keys
- Can be passed as a parameter or via
AIRIA_API_KEYenvironment variable - Support gateway functionality (OpenAI and Anthropic gateways)
- Suitable for long-term, persistent authentication
Bearer Tokens
- Must be provided explicitly (no environment variable fallback)
- Important: Bearer tokens cannot be used with gateway functionality
- Suitable for ephemeral, short-lived authentication scenarios
- Ideal for temporary access or programmatic token generation
Gateway Usage
Airia provides gateway capabilities for popular AI services like OpenAI and Anthropic, allowing you to use your Airia API key with these services.
Note: Gateway functionality requires API key authentication. Bearer tokens are not supported for gateway usage.
# ✅ API key with gateway support
client = AiriaClient.with_openai_gateway(api_key="your_api_key")
# ❌ Bearer token with gateway - NOT SUPPORTED
# client = AiriaClient.with_openai_gateway(bearer_token="token") # This won't work
OpenAI Gateway
from airia import AiriaClient
# Initialize client with OpenAI gateway support
client = AiriaClient.with_openai_gateway(api_key="your_airia_api_key")
# Use OpenAI's API through Airia's gateway
response = client.openai.chat.completions.create(
model="gpt-4.1-nano",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"},
]
)
print(response.choices[0].message.content)
Anthropic Gateway
from airia import AiriaClient
# Initialize client with Anthropic gateway support
client = AiriaClient.with_anthropic_gateway(api_key="your_airia_api_key")
# Use Anthropic's API through Airia's gateway
response = client.anthropic.messages.create(
model="claude-3-5-haiku-20241022",
max_tokens=1000,
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.content[0].text)
You can set the Gateway URL by passing the gateway_url parameter when using the gateway constructors. The default values are https://gateway.airia.ai/openai/v1 for OpenAI and https://gateway.airia.ai/anthropic for Anthropic.
Asynchronous Gateway Usage
Both gateways also support asynchronous usage:
import asyncio
from airia import AiriaAsyncClient
async def main():
# Initialize async client with gateway support
client = AiriaAsyncClient.with_openai_gateway(api_key="your_airia_api_key")
# Use OpenAI's API asynchronously through Airia's gateway
response = await client.openai.chat.completions.create(
model="gpt-4.1-nano",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"},
]
)
print(response.choices[0].message.content)
asyncio.run(main())