Why AI gateway?
Instead of managing API keys per-model and per-environment, the AI Gateway provides a centralized, authenticated entry point for all LLM interactions. It handles authentication, agent ID validation, and policy enforcement - while maintaining full OpenAI SDK compatibility.The gateway wraps the OpenAI SDK - any framework that works with OpenAI works with AI Gateway. No code changes required.
Prerequisite: Ensure you’ve installed the SDK and configured your environment before proceeding.
Quick start
1. Set up environment variables
Before using the gateway, configure your credentials:.env
2. Make your first call
That’s it - you’re making LLM calls through the Backbase AI Platform.
Tracing with observability
Callconfigure_observability() before creating the gateway (integration steps):
Sync vs Async
Choose based on your application architecture:- Sync
- Async
Use
AIGateway for synchronous applications (scripts, simple APIs):Common use cases
Streaming responses
For real-time responses (chatbots, interactive UIs), enable streaming:- Sync streaming
- Async streaming
Framework adapters
The AI Gateway is OpenAI-compatible out of the box, but if you’re using LangChain, LangGraph, or Agno, adapters convert the gateway into framework-native objects - no manual configuration required.LangChain
LangGraph
Agno
Common patterns
Token usage tracking
Extract token consumption from responses:Error handling
Handle errors gracefully using the SDK’s specific exception types for different failure scenarios:Error types reference
Configuration
Environment variables
Configure credentials via environment variables (recommended):.env
Create parameters
string
required
Model identifier (e.g.,
gpt-4o, gpt-4o-mini, gpt-4-turbo).string
required
Your agent’s unique identifier in UUID v4 format. Obtained from the platform when you register your agent.
string
API key for authentication. Falls back to
AI_GATEWAY_API_KEY, then AZURE_OPENAI_API_KEY, if not provided.string
Gateway URL. Falls back to
AI_GATEWAY_ENDPOINT environment variable or platform default.string
default:"2024-10-21"
API version for the gateway.
Advanced: Accessing the underlying client
Access the underlying OpenAI client or raw configuration for advanced use cases:Get_client()
Get the underlying OpenAI client for direct SDK access:Get_config()
Get configuration dictionary for manual framework setup:API reference
Aigateway
Asyncaigateway
Same interface asAIGateway but returns AsyncOpenAI client and supports async operations.
Next steps
Observability
Add tracing and monitoring to your agents
Starter kits
See AI Gateway integrated in production templates
Get started
Build your first agent end-to-end
Examples
View complete working examples