Skip to main content
Provider Slug. x-ai

Integrate

Just paste your xAI API Key to Obiguard to create your Virtual Key.

Sample Request

Obiguard is a drop-in replacement for xAI. You can make request using the official Obiguard SDK.
Popular libraries & agent frameworks like LangChain, CrewAI, AutoGen, etc. are also supported.
  • Python SDK
  • OpenAI SDK
  • cURL
Python
from obiguard import Obiguard

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

response = client.chat.completions.create(
  model="grok-beta",
  messages=[{"role": "user", "content": "Hello!"}]
)

print(response.choices[0].message)

Integration Overview

xAI Endpoints & Capabilities

Obiguard works with all of xAI’s endpoints and supports all xAI capabilities like function calling and image understanding. Find examples for each below:
  • Python SDK
  • cURL
Python
tools = [{
  "type": "function",
  "function": {
    "name": "getWeather",
    "description": "Get the current weather",
    "parameters": {
      "type": "object",
      "properties": {
        "location": {"type": "string", "description": "City and state"},
        "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
      },
      "required": ["location"]
    }
  }
}]

response = client.chat.completions.create(
  model="grok-beta",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "What's the weather like in Delhi - respond in JSON"}
  ],
  tools=tools,
  tool_choice="auto"
)

print(response.choices[0].finish_reason)
Process images alongside text using xAI’s vision capabilities:
  • Python SDK
  • cURL
Python
response = client.chat.completions.create(
  model="grok-beta",
  messages=[
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "What's in this image?"},
        {
          "type": "image_url",
          "image_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
        },
      ],
    }
  ],
  max_tokens=300,
)

print(response)
Generate embeddings for text using xAI’s embedding models:Coming Soon!

FAQs

You can sign up to xAI here and grab your API key.
xAI typically gives some amount of free credits without you having to add your credit card. Reach out to their support team if you’d like additional free credits.
You can find your current rate limits imposed by xAI on the console.