> ## 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.

# Authentication

To ensure secure access to Obiguard's APIs, authentication is required for all requests.
This guide provides the necessary steps to authenticate your requests using the Obiguard API key,
regardless of whether you are using the SDKs for Python, the OpenAI SDK, or making REST API calls directly.

## Obtaining Your API Key

[Create](https://app.obiguard.ai/sign-up) or [log in](https://app.obiguard.ai/sign-in) to your Obiguard account.
Grab your account's API key from a guardrail policy, or create a virtual key.

## Authentication with SDKs

### Obiguard SDKs

<Tabs>
  <Tab title="Python SDK">
    ```python theme={null}
        from obiguard import Obiguard

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

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

    print(chat_completion.choices[0].message["content"])
    ```
  </Tab>

  <Tab title="cURL">
    ```sh theme={null}
    curl https://gateway.obiguard.ai/v1/chat/completions \
      -H "Content-Type: application/json" \
      -H "x-obiguard-api-key: $Obiguard_API_KEY" \
      -d '{
        "model": "gpt-4o",
        "messages": [
          { "role": "system", "content": "You are a helpful assistant." },
          { "role": "user", "content": "Hello!" }
        ]
      }'
    ```
  </Tab>
</Tabs>

### OpenAI SDK

When integrating Obiguard through the OpenAI SDK, modify the base URL and add the `x-obiguard-api-key` header for authentication.
Here's an example of how to do it:

<Info>
  We use the `createHeaders` helper function from the Obiguard SDK here to easily create Obiguard headers.

  You can pass the raw headers (`x-obiguard-api-key`, `x-obiguard-provider`) directly in the `defaultHeaders` param as well.
</Info>

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from openai import OpenAI
    from obiguard import OBIGUARD_GATEWAY_URL, createHeaders

    openai_client = OpenAI(
      base_url=Obiguard_GATEWAY_URL,
      default_headers=createHeaders(
        obiguard_api_key="vk-obg***",  # Your Obiguard virtual key
        provider="openai"
      )
    )
    response = openai_client.chat.completions.create(
      messages=[{'role': 'user', 'content': 'Say this is a test'}],
      model='gpt-4bo'
    )
    ```
  </Tab>
</Tabs>

Read more [here](/integrations/llms/openai).
