Skip to main content
Get up and running with AI Gateway and Observability in minutes. This guide shows you how to set up both features with one complete example.

Prerequisites

Installation Guide

Configure your project to pull from Backbase Artifactory and install the SDK.

Quick Setup

1. Configure Environment Variables

Create a .env file with your credentials:
.env
# AI Gateway Configuration (Required)
AI_GATEWAY_API_KEY=your-api-key
AI_GATEWAY_ENDPOINT=your-ai-gateway-endpoint

# Observability Configuration (Required for tracing)
LANGFUSE_PUBLIC_KEY=pk-lf-xxx
LANGFUSE_SECRET_KEY=sk-lf-xxx
LANGFUSE_HOST=https://cloud.langfuse.com
Never commit .env files to version control. Ensure .env is in your .gitignore.

2. Create Your First Agent

Create agent.py with AI Gateway and Observability:
agent.py
from bb_ai_sdk.observability import init
from bb_ai_sdk.ai_gateway import AIGateway

# Initialize observability first (enables automatic tracing)
init(agent_name="my-first-agent")

# Create AI Gateway client
gateway = AIGateway.create(
    model_id="gpt-4o",
    agent_id="550e8400-e29b-41d4-a716-446655440000"
)

# Make your first LLM call (automatically traced)
response = gateway.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello, World!"}]
)

print(response.choices[0].message.content)

3. Run Your Agent

source .env
uv run python agent.py
If you see a response, you’ve successfully connected to the AI Gateway! Check your LangFuse dashboard to see the trace.

What Happens Next?

When you initialize observability before creating the AI Gateway, all LLM calls are automatically traced—no additional code required. This integration gives you:
  • AI Gateway: Routes your LLM calls through the Backbase AI Platform with automatic authentication, agent ID validation, and policy enforcement
  • Automatic Tracing: Every gateway call appears in LangFuse with full context: tokens, latency, cost, and request/response data
  • Zero Configuration: The SDK handles instrumentation automatically—just initialize observability first
The observability module auto-instruments AI Gateway calls. Initialize init() before creating gateway instances to ensure all calls are captured from the start.

Customize Your Setup

  • AI Gateway: Configure streaming, tools, framework adapters, error handling, and advanced client options
  • Observability: Add custom tracing, configure backends (Datadog, Grafana), set up framework callbacks, and tune export settings

Next Steps