> ## Documentation Index
> Fetch the complete documentation index at: https://docs.obiguard.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Obiguard Python SDK

> Official Obiguard Python SDK to help take your AI apps to production

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.

<CardGroup cols={3}>
  <Card horizontal icon="badge-check">Official</Card>
  <Card horizontal icon="python" href="https://pypi.org/project/obiguard"> ![](https://img.shields.io/pypi/v/portkey.svg) </Card>
</CardGroup>

## Installation

Install the Obiguard SDK from PyPI:

```bash theme={null}
pip install obiguard
```

## API Key Setup

1. [Create a Obiguard API key](https://app.obiguard.ai) in your dashboard.
2. Store your API key securely as an environment variable:

<CodeGroup>
  ```sh macOS/Linux theme={null}
  export OBIGUARD_API_KEY="your_api_key_here"
  ```

  ```sh Windows(PowerShell) theme={null}
  setx OBIGUARD_API_KEY "your_api_key_here"
  ```
</CodeGroup>

<Info>The SDK automatically detects your API key from the environment.</Info>

## Quickstart

Here’s a minimal example to get you started:

```python theme={null}
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
)
```

<Info> You can use either a Virtual Key or a Config object to select your AI provider.
Find more info on different authentication mechanisms
[here](/api-reference/inference-api/headers#provider-authentication).</Info>

## 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](/virtual-keys) 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.

```python theme={null}
# 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`:

```py Python theme={null}
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.

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

**Example: Disable SSL Verification**

```python theme={null}
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](https://github.com/openai/openai-python#configuring-the-http-client) for more examples and best practices.

## Parameters

<Card title="List of All Headers" icon="list" href="/api-reference/inference-api/headers#list-of-all-headers">
  View the complete list of headers that can be used with Obiguard API requests, including authentication,
  configuration, and custom headers.
</Card>

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

```python theme={null}
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

* Having trouble? [Email support](mailto:support@obiguard.com).

## FAQs

<AccordionGroup>
  <Accordion title="Can I use this SDK with OpenAI-compatible code?">
    Yes! Obiguard’s Python SDK is OpenAI-compatible. You can also use any OpenAI-compatible library by pointing it to
    the Obiguard API endpoint and using your Obiguard API key.
  </Accordion>

  <Accordion title="How do I fix CERTIFICATE_VERIFY_FAILED or SSL errors?">
    If you are behind a VPN (like Zscaler) or a corporate proxy and see SSL/certificate errors, you can pass a custom
    `httpx.Client` to the Obiguard SDK with SSL verification disabled. See the docs above for an example. **Warning:**
    Disabling SSL verification is insecure—only use this as a last resort or for debugging.
  </Accordion>

  <Accordion title="Where can I find more examples?">
    Check out our integration docs [here](/integrations/ecosystem).
  </Accordion>
</AccordionGroup>
