python -m pip install anthropicimport os
import anthropic
api_key = os.environ.get("GUARD_API_KEY")
if not api_key:
raise RuntimeError("GUARD_API_KEY is not set")
client = anthropic.Anthropic(
api_key=api_key,
base_url="https://api.guardrelay.ai",
)
message = client.messages.create(
model="claude-sonnet-5",
max_tokens=64,
messages=[{"role": "user", "content": "Hello!"}],
)
print(message.content)python -m pip install openaiimport os
from openai import OpenAI
api_key = os.environ.get("GUARD_API_KEY")
if not api_key:
raise RuntimeError("GUARD_API_KEY is not set")
client = OpenAI(
api_key=api_key,
base_url="https://api.guardrelay.ai/v1",
)
response = client.chat.completions.create(
model="k3",
messages=[{"role": "user", "content": "Hello!"}],
max_tokens=128,
)
print(response.choices[0].message.content)Kimi speaks both Chat Completions and the Anthropic Messages protocol, so both the openai package and the anthropic package fit: the only difference is the base URL, which carries no /v1 for anthropic. Below is the openai variant as the more familiar one. The base URL must carry /v1, the key is the same gd-…, and model takes one of the four ids.
model value | Context window |
|---|---|
k3 | 1,048,576 tokens |
k3-256k | 262,144 tokens |
kimi-for-coding | 262,144 tokens |
kimi-for-coding-highspeed | 262,144 tokens |
Reasoning depth is set by reasoning_effort, and all four models accept it: the value reaches the wire as sent, and Kimi itself documents the levels low, high and max. On kimi-for-coding and kimi-for-coding-highspeed there is also the thinking field, exactly as {"type": "enabled", "keep": "all"}; on the K3 models it is rejected. Details are on Thinking / effort.
response = client.chat.completions.create(
model="k3",
messages=[{"role": "user", "content": "Break this task down step by step"}],
max_tokens=1024,
reasoning_effort="high",
stream=True,
)
for chunk in response:
piece = chunk.choices[0].delta.content
if piece:
print(piece, end="")Composer and Grok work on all three surfaces, so both anthropic and openai fit. They do accept the tools field: the model returns a call, and running it and returning the result is your code's job.
import os
from openai import OpenAI
api_key = os.environ.get("GUARD_API_KEY")
if not api_key:
raise RuntimeError("GUARD_API_KEY is not set")
client = OpenAI(
api_key=api_key,
base_url="https://api.guardrelay.ai/v1",
)
response = client.chat.completions.create(
model="cursor-grok-4.6-high",
messages=[{"role": "user", "content": "Hi!"}],
max_tokens=128,
)
print(response.choices[0].message.content)