The official Python SDK makes it easy to integrate Obiguard into any Python application. Enjoy unified access to 250+ LLMs, advanced observability, routing, governance, and enterprise features with just a few lines of code.

Official

Installation

Install the Obiguard SDK from PyPI:

pip install obiguard

API Key Setup

  1. Create a Obiguard API key in your dashboard.
  2. Store your API key securely as an environment variable:
export OBIGUARD_API_KEY="your_api_key_here"
The SDK automatically detects your API key from the environment.

Quickstart

Here’s a minimal example to get you started:

from obiguard import Obiguard

client = Obiguard(
    obiguard_api_key="sk-obg***",  # Your Obiguard API or virtual key
)

response = client.chat.completions.create(
    messages=[{"role": "user", "content": "Hello, world!"}],
    model="gpt-4o"  # Example provider/model
)
You can use either a Virtual Key or a Config object to select your AI provider. Find more info on different authentication mechanisms here.

Authentication & Configuration

The SDK requires:

  • Obiguard API Key: Your Obiguard API key (env var OBIGUARD_API_KEY recommended)
  • Provider Authentication:
  • Virtual Key: The Virtual Key of your chosen AI provider
  • Provider Slug + Auth Headers: Useful if you do not want to save your API keys to Obiguard and make direct requests.
# With Virtual Key
client = Obiguard(obiguard_api_key="...")

# With Provider Slug + Auth Headers
client = Obiguard(obiguard_api_key="...", provider="openai", Authorization = "Bearer OPENAI_API_KEY")

Async Usage

Obiguard supports Async usage - just use AsyncObiguard client instead of Obiguard with await:

Python
import asyncio
from obiguard import AsyncObiguard

client = AsyncObiguard(
    obiguard_api_key="vk-obg***",  # Your Obiguard virtual key
)

async def main():
    chat_completion = await client.chat.completions.create(
        messages=[{'role': 'user', 'content': 'Say this is a test'}],
        model='gpt-4'
    )

    print(chat_completion)

asyncio.run(main())

Using a Custom httpx Client

If you need to customize HTTP networking—for example, to disable SSL verification due to VPNs like Zscaler or to use custom proxies—you can pass your own httpx.Client to the Obiguard SDK.

Disabling SSL certificate verification is insecure and should only be used for debugging or in trusted internal environments. Never use this in production.

Example: Disable SSL Verification

import httpx
from obiguard import Obiguard

# Create an httpx client with SSL verification disabled
custom_client = httpx.Client(verify=False)

client = Obiguard(
    obiguard_api_key="vk-obg***",  # Your Obiguard virtual key
    http_client=custom_client
)

response = client.chat.completions.create(
    messages=[{"role": "user", "content": "Hello!"}],
    model="gpt-4o"
)
print(response)
  • You can use any httpx.Client options (e.g., for proxies, timeouts, custom headers).
  • For async usage, pass an httpx.AsyncClient to AsyncObiguard.
  • See OpenAI Python SDK: Configuring the HTTP client for more examples and best practices.

Parameters

List of All Headers

View the complete list of headers that can be used with Obiguard API requests, including authentication, configuration, and custom headers.

Here’s how you can use these headers with the Python SDK:

portkey = Obiguard(
    obiguard_api_key="vk-obg***",  # Your Obiguard virtual key
    # Add any other headers from the reference
)

# Or at runtime
completion = portkey.with_options(
    metadata={"_user": "user_id"},
    # Add any other headers as needed
).chat.completions.create(
    messages=[{"role": "user", "content": "Hello!"}],
    model="gpt-4o"
)

Troubleshooting & Support

FAQs