Proxy Overview
Proxy Overview
Debug your AI agents without changing a single line of code. The Opswald proxy sits between your application and LLM providers, automatically capturing every API call as structured traces.
How It Works
Your App → Opswald Proxy → OpenAI/Anthropic → Response → Proxy → Your App ↓ Opswald DashboardThe proxy:
- Intercepts all HTTP requests to LLM providers
- Captures request/response data as spans
- Forwards requests to the original provider unchanged
- Sends trace data to Opswald for debugging
Zero Code Changes
Just change your base URL:
# Beforeimport openaiclient = openai.OpenAI(base_url="https://api.openai.com/v1")
# Afterimport openaiclient = openai.OpenAI(base_url="https://proxy.opswald.com/openai")// Beforeimport OpenAI from 'openai';const client = new OpenAI({ baseURL: "https://api.openai.com/v1" });
// Afterimport OpenAI from 'openai';const client = new OpenAI({ baseURL: "https://proxy.opswald.com/openai" });Your API key stays the same. Your code stays the same. Only the URL changes.
Supported Providers
| Provider | Proxy URL | Original URL |
|---|---|---|
| OpenAI | https://proxy.opswald.com/openai | https://api.openai.com/v1 |
| Anthropic | https://proxy.opswald.com/anthropic | https://api.anthropic.com |
| Google AI | https://proxy.opswald.com/google | https://generativelanguage.googleapis.com |
What Gets Captured
Every API call becomes a span with:
Request Data
- Model used (
gpt-4o,claude-3-sonnet, etc.) - Input tokens (cost calculated server-side during ingestion)
- Parameters (temperature, max_tokens, etc.)
- Messages (with content filtering options)
Response Data
- Generated content (with filtering options)
- Output tokens (cost calculated server-side during ingestion)
- Response time and latency
- Finish reason (completed, length, etc.)
Metadata
- Timestamp and duration
- User ID (if provided in headers)
- Session ID (if provided in headers)
- Error details (for failed requests)
Quick Start
1. Get Your Proxy Token
curl -X POST https://api.opswald.com/v1/proxy/tokens \ -H "Authorization: Bearer your-opswald-api-key" \ -H "Content-Type: application/json" \ -d '{ "name": "my-app-proxy", "description": "Proxy token for my AI application" }'2. Configure Your Application
Add these headers to your LLM requests:
import openai
client = openai.OpenAI( base_url="https://proxy.opswald.com/openai", default_headers={ "X-Opswald-Key": "your-proxy-token", "X-Opswald-Session": "user-session-123", # Optional "X-Opswald-User": "user-456" # Optional })3. Make Requests Normally
# This call is now automatically tracedresponse = client.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": "Hello!"}])4. View Traces in Dashboard
Go to app.opswald.com to see your traces appear in real-time.
Content Filtering
Control what content gets captured for privacy:
client = openai.OpenAI( base_url="https://proxy.opswald.com/openai", default_headers={ "X-Opswald-Key": "your-proxy-token", "X-Opswald-Filter-Input": "hash", # hash|truncate|omit|full "X-Opswald-Filter-Output": "truncate" # hash|truncate|omit|full })Filter Options
| Option | Input Behavior | Output Behavior |
|---|---|---|
full | Capture complete content | Capture complete content |
truncate | First 200 chars + ”…” | First 200 chars + ”…” |
hash | SHA-256 hash only | SHA-256 hash only |
omit | No content captured | No content captured |
Session and User Tracking
Group related calls and identify users:
# Track user sessionsclient = openai.OpenAI( base_url="https://proxy.opswald.com/openai", default_headers={ "X-Opswald-Key": "your-proxy-token", "X-Opswald-Session": f"chat-{session_id}", "X-Opswald-User": f"user-{user_id}", "X-Opswald-Trace": "customer-support-flow" # Groups spans into traces })
# All subsequent requests in this conversation will be groupedresponse1 = client.chat.completions.create(...) # Span 1response2 = client.chat.completions.create(...) # Span 2response3 = client.chat.completions.create(...) # Span 3Error Handling
The proxy handles errors gracefully:
Provider Errors
If OpenAI/Anthropic returns an error, the proxy:
- Captures the error in a span
- Forwards the exact error to your app
- Preserves all error details and status codes
Proxy Errors
If the proxy itself fails:
- Fallback requests go directly to the provider
- No interruption to your application
- Error logged but doesn’t break your workflow
Custom Metadata
Add custom context to your traces:
client = openai.OpenAI( base_url="https://proxy.opswald.com/openai", default_headers={ "X-Opswald-Key": "your-proxy-token", "X-Opswald-Meta-Environment": "production", "X-Opswald-Meta-Version": "v2.1.0", "X-Opswald-Meta-Feature": "customer-chat", "X-Opswald-Meta-User-Tier": "enterprise" })Custom metadata appears in the dashboard for filtering and analysis.
Streaming Support
The proxy fully supports streaming responses:
# Streaming works transparentlystream = client.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": "Tell me a story"}], stream=True)
for chunk in stream: print(chunk.choices[0].delta.content) # Each chunk is captured, final span shows complete responseFramework Integration
LangChain
from langchain.llms import OpenAI
llm = OpenAI( openai_api_base="https://proxy.opswald.com/openai", openai_api_key="your-openai-key", # Your real OpenAI key headers={ "X-Opswald-Key": "your-proxy-token", "X-Opswald-Session": "langchain-session" })
# All LangChain LLM calls now traced automaticallyresponse = llm("What is the capital of France?")Haystack
from haystack.nodes import PromptNode
prompt_node = PromptNode( model_name_or_path="gpt-4o", api_key="your-openai-key", api_base="https://proxy.opswald.com/openai", default_headers={ "X-Opswald-Key": "your-proxy-token" })Guidance
import guidance
# Configure guidance to use proxyguidance.llm = guidance.llms.OpenAI( api_base="https://proxy.opswald.com/openai", api_key="your-openai-key", headers={"X-Opswald-Key": "your-proxy-token"})Self-Hosted Proxy
Deploy your own proxy instance for maximum control:
# Dockerdocker run -d -p 8080:8080 \ -e OPSWALD_API_KEY=your-key \ -e OPSWALD_API_URL=https://api.opswald.com \ opswald/proxy:latest
# Your base URL becomes# http://localhost:8080/openai/v1See Configuration for full deployment options.
Benefits
For Development
- See every LLM call without code changes
- Debug conversation flows across multiple requests
- Monitor token usage and costs in real-time
- Identify bottlenecks with request timing
For Production
- Track user interactions with session grouping
- Monitor error rates and failure patterns
- Review LLM usage patterns for debugging
- Performance monitoring with latency metrics
For Debugging
- Zero setup time - just change the URL
- Complete conversation history in one view
- Error reproduction with exact request data
- A/B testing different models or parameters
The proxy gives you instant visibility into any LLM-powered application, making it the fastest way to start debugging AI agents.