Skip to content
Connect a clientPython SDK

Python SDK

Python SDK for the selected model family.

Set up with your own AI
Model protocol
bash
python -m pip install anthropic
python
import 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)
bash
python -m pip install openai
python
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="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 valueContext window
k31,048,576 tokens
k3-256k262,144 tokens
kimi-for-coding1,048,576 tokens
kimi-for-coding-highspeed262,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.

python
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.

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

Python SDK for GLM

Use the OpenAI SDK for Responses and Chat, and the Anthropic SDK for Messages. Keep the key only in GUARD_API_KEY.

bash
python -m pip install openai anthropic
python
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.responses.create(
    model="glm-5.3",
    input="Reply with OK",
    max_output_tokens=4096,
    store=False,
)
print(response.output_text)

Standalone Chat Completions example:

python
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:

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

Python SDK for Gemini

Use the OpenAI SDK for Chat Completions and Responses, and the Anthropic SDK for Messages. Keep the key only in GUARD_API_KEY.

bash
python -m pip install openai anthropic
python
import 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:

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

Python SDK for Muse

Use the OpenAI SDK for Chat Completions and Responses, and the Anthropic SDK for Messages. Keep the key only in GUARD_API_KEY.

bash
python -m pip install openai anthropic
python
import 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:

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

Sections

On this page