Configuration
The InfraPrism SDK can be configured through environment variables, client initialization parameters, or a combination of both.
Environment Variables
| Variable | Description | Required |
|---|---|---|
INFRAPRISM_API_KEY | Your InfraPrism API key | Yes |
OPENAI_API_KEY | OpenAI API key (for OpenAI provider) | Provider-specific |
ANTHROPIC_API_KEY | Anthropic API key (for Anthropic provider) | Provider-specific |
INFRAPRISM_ENVIRONMENT | Environment tag (e.g., production, staging) | No |
INFRAPRISM_DISABLED | Set to true to disable tracking | No |
INFRAPRISM_DEBUG | Set to true for debug logging | No |
Client Initialization
OpenAI
from infraprism import InfraPrismOpenAI
client = InfraPrismOpenAI(
# OpenAI configuration
api_key="sk-...", # OpenAI API key
organization="org-...", # OpenAI organization (optional)
base_url="https://api.openai.com/v1", # Custom base URL (optional)
timeout=30.0, # Request timeout in seconds
max_retries=2, # Number of retries
# InfraPrism configuration
infraprism_api_key="ip-...", # InfraPrism API key
infraprism_environment="production", # Environment tag
infraprism_disabled=False, # Disable tracking
infraprism_debug=False, # Enable debug logging
)
Anthropic
from infraprism import InfraPrismAnthropic
client = InfraPrismAnthropic(
# Anthropic configuration
api_key="sk-ant-...", # Anthropic API key
timeout=30.0,
max_retries=2,
# InfraPrism configuration
infraprism_api_key="ip-...",
infraprism_environment="production",
)
Configuration Options
infraprism_api_key
Your InfraPrism API key. Get one from the dashboard.
client = InfraPrismOpenAI(infraprism_api_key="ip-your-key")
Or use an environment variable (recommended):
export INFRAPRISM_API_KEY="ip-your-key"
infraprism_environment
Tag all requests with an environment name. Useful for separating development, staging, and production costs.
client = InfraPrismOpenAI(infraprism_environment="production")
The environment is automatically added as a tag and can be filtered in the dashboard.
infraprism_disabled
Completely disable InfraPrism tracking. Useful for local development or testing.
client = InfraPrismOpenAI(infraprism_disabled=True)
Or via environment variable:
export INFRAPRISM_DISABLED=true
When disabled, the SDK behaves exactly like the native OpenAI/Anthropic client with zero overhead.
infraprism_debug
Enable debug logging to troubleshoot integration issues.
client = InfraPrismOpenAI(infraprism_debug=True)
Debug mode logs:
- Event payloads being sent
- Batch upload timing
- Any errors in the tracking pipeline
Async Configuration
The async clients accept the same configuration options:
from infraprism import AsyncInfraPrismOpenAI
client = AsyncInfraPrismOpenAI(
infraprism_api_key="ip-...",
infraprism_environment="production",
)
# Use with async/await
response = await client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello"}],
entity_type="customer",
entity_id="acme-corp",
)
Request-Level Configuration
You can override configuration on a per-request basis:
# Override entity and tags for this specific request
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello"}],
entity_type="project", # Override entity type
entity_id="internal-tools", # Override entity ID
tags={"priority": "low"}, # Request-specific tags
infraprism_disabled=True, # Skip tracking for this call
)
Configuration Precedence
Configuration is resolved in this order (highest to lowest priority):
- Request-level parameters
- Client initialization parameters
- Environment variables
- Default values
Next Steps
- OpenAI Provider - OpenAI-specific configuration
- Anthropic Provider - Anthropic-specific configuration
- Azure OpenAI - Azure configuration