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 or log 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

    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"])

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:

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.

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'
)

Read more here.