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-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 | 1,048,576 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)Use the OpenAI SDK for Responses and Chat, and the Anthropic SDK for Messages. Keep the key only in GUARD_API_KEY.
python -m pip install openai anthropicimport os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["GUARD_API_KEY"],
base_url="https://api.guardrelay.ai/glm/v1",
max_retries=0,
)
response = client.responses.create(
model="glm-5.3",
input="Reply with OK",
max_output_tokens=4096,
store=False,
)
print(response.output_text)Standalone Chat Completions example:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["GUARD_API_KEY"],
base_url="https://api.guardrelay.ai/glm/v1",
max_retries=0,
)
response = client.chat.completions.create(
model="glm-5.3",
messages=[{"role": "user", "content": "Reply with OK"}],
max_tokens=4096,
)
print(response.choices[0].message.content)Messages uses a Base URL without /v1:
import anthropic
client = anthropic.Anthropic(
api_key=os.environ["GUARD_API_KEY"],
base_url="https://api.guardrelay.ai/glm",
max_retries=0,
)
message = client.messages.create(
model="glm-5.3",
max_tokens=4096,
messages=[{"role": "user", "content": "Reply with OK"}],
)
print("".join(block.text for block in message.content if block.type == "text"))Use the OpenAI SDK for Chat Completions and Responses, and the Anthropic SDK for Messages. Keep the key only in GUARD_API_KEY.
python -m pip install openai anthropicimport os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["GUARD_API_KEY"],
base_url="https://api.guardrelay.ai/v1",
max_retries=0,
)
response = client.chat.completions.create(
model="gemini-4-argon",
messages=[{"role": "user", "content": "Reply with OK"}],
max_tokens=4096,
)
print(response.choices[0].message.content)Messages uses a Base URL without /v1:
import os
import anthropic
client = anthropic.Anthropic(
api_key=os.environ["GUARD_API_KEY"],
base_url="https://api.guardrelay.ai",
max_retries=0,
)
message = client.messages.create(
model="gemini-4-argon",
max_tokens=4096,
messages=[{"role": "user", "content": "Reply with OK"}],
)
print("".join(block.text for block in message.content if block.type == "text"))Use the OpenAI SDK for Chat Completions and Responses, and the Anthropic SDK for Messages. Keep the key only in GUARD_API_KEY.
python -m pip install openai anthropicimport os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["GUARD_API_KEY"],
base_url="https://api.guardrelay.ai/v1",
max_retries=0,
)
response = client.chat.completions.create(
model="muse-wonder-1.0",
messages=[{"role": "user", "content": "Reply with OK"}],
max_tokens=4096,
)
print(response.choices[0].message.content)Messages uses a Base URL without /v1:
import os
import anthropic
client = anthropic.Anthropic(
api_key=os.environ["GUARD_API_KEY"],
base_url="https://api.guardrelay.ai",
max_retries=0,
)
message = client.messages.create(
model="muse-wonder-1.0",
max_tokens=4096,
messages=[{"role": "user", "content": "Reply with OK"}],
)
print("".join(block.text for block in message.content if block.type == "text"))