Obiguard works with all of xAI’s endpoints and supports all xAI capabilities like function calling and image understanding. Find examples for each below:
Tool Calling (Function Calling)
Python
Copy
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)
Python
Copy
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)
REST
Copy
curl -X POST "https://gateway.obiguard.ai/v1/chat/completions" \ -H "Content-Type: application/json" \ -H "x-obiguard-api-key: $OBIGUARD_API_KEY" \ -d '{ "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": [{ "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"] } } }], "tool_choice": "auto" }'
Vision
Process images alongside text using xAI’s vision capabilities:
You can sign up to xAI here and grab your API key.
Is is free to use the xAI 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.
I am getting rate limited on xAI API
You can find your current rate limits imposed by xAI on the console.
Assistant
Responses are generated using AI and may contain mistakes.