Strands Agents
Run Strands Agents on OpenRelay models from Python or TypeScript through the SDK's OpenAI provider, with tools, streaming and structured output.
Strands Agents runs on OpenRelay through the SDK's built-in OpenAI model provider. Point the provider at OpenRelay's Chat Completions endpoint and pass your OpenRelay API key. There is no OpenRelay package to install.
Install
pip install 'strands-agents[openai]'Create an API key in the dashboard and export it. Inference is prepaid, so add funds before the first request.
export OPENRELAY_API_KEY="or_your_api_key"Create the model
Set the base URL to https://inference.openrelay.inc/v1 and the model id to an
OpenRelay model id. Model ids carry the openrelay/ prefix: a bare id such as
kimi-k3.1-pro returns 404 with model_not_found.
import os
from strands import Agent
from strands.models.openai import OpenAIModel
model = OpenAIModel(
client_args={
"api_key": os.environ["OPENRELAY_API_KEY"],
"base_url": "https://inference.openrelay.inc/v1",
},
model_id="openrelay/kimi-k3.1-pro",
params={"max_tokens": 4096},
)
agent = Agent(model=model, callback_handler=None)
result = agent("Explain tool calling in one sentence.")
print(result)In TypeScript, api: 'chat' selects the Chat Completions API; the provider
defaults to the Responses API otherwise. callback_handler=None (Python) and
printer: false (TypeScript) turn off the agent's default printing to stdout,
so the script prints only the answer.
The token limit (max_tokens in Python, maxTokens in TypeScript) counts
reasoning tokens too. Set it high enough for the reasoning and the answer: a
limit the reasoning uses up returns an empty answer.
Streaming
The provider streams from OpenRelay by default. To handle text as it arrives,
iterate over the agent's events. The examples from here on reuse the model
from above.
import asyncio
agent = Agent(model=model, callback_handler=None)
async def main():
async for event in agent.stream_async("Name three uses of a hash map."):
if "data" in event:
print(event["data"], end="", flush=True)
print()
asyncio.run(main())Tools
Define a tool and pass it to the agent. The model returns a tool call, Strands runs the function, and the model answers from its result.
from strands import Agent, tool
@tool
def get_temperature(city: str) -> dict:
"""Get the current temperature for a city.
Args:
city: The city name.
"""
return {"city": city, "temperature_celsius": 18}
agent = Agent(model=model, tools=[get_temperature], callback_handler=None)
result = agent("What is the temperature in Paris?")
print(result)Structured output
Pass a schema and read the validated object from the result. Strands gets structured output through a tool call, so use a model that supports tool calling: Kimi K3.1 Pro, DeepSeek V4.1 Flash, GLM-5.3-Flash or Gemma 4 31B.
from pydantic import BaseModel
class Person(BaseModel):
name: str
age: int
occupation: str
agent = Agent(model=model, callback_handler=None)
result = agent(
"Ada Park is a 34-year-old structural engineer.",
structured_output_model=Person,
)
print(result.structured_output)Reasoning
OpenRelay returns a model's reasoning in reasoning_content. The Python
provider reads it as reasoning content; the TypeScript provider with
api: 'chat' reads only the answer text. Either way, reasoning tokens bill as
output. Set reasoning_effort in params to control reasoning:
openrelay/kimi-k3.1-proandopenrelay/deepseek-v4.1-flashreason by default.reasoning_efforttakesnone(off),low,highormax.openrelay/glm-5.3-flashalways reasons;reasoning_efforthas no effect.openrelay/gemma-4-31bdoes not reason by default. Setreasoning_efforttolow,highormaxto turn it on.
model = OpenAIModel(
client_args={
"api_key": os.environ["OPENRELAY_API_KEY"],
"base_url": "https://inference.openrelay.inc/v1",
},
model_id="openrelay/deepseek-v4.1-flash",
params={"max_tokens": 4096, "reasoning_effort": "none"},
)Models
Tool calling and structured output work on openrelay/kimi-k3.1-pro,
openrelay/deepseek-v4.1-flash, openrelay/glm-5.3-flash and
openrelay/gemma-4-31b. Models lists every model id
with its context window and inputs, and Pricing has
the rates.
What to expect
- Usage. The final streamed chunk carries
usage, and Strands adds it to the result's metrics (result.metrics.accumulated_usagein Python,result.metrics.accumulatedUsagein TypeScript). - Prompt caching. The chat models cache prompt prefixes automatically, with
no request setting. An agent resends the conversation on every turn, so later
turns report cached tokens (
cacheReadInputTokens), which bill at the cached-input rate. - Reasoning on later turns. The Python provider drops reasoning from earlier
turns when it sends the conversation back, and logs
reasoningContent is not supported in multi-turn conversations with the Chat Completions API. The request still succeeds. - Penalties.
openrelay/kimi-k3.1-prorejectsfrequency_penaltyandpresence_penaltywith a400, so leave them unset for that model.
Vercel AI SDK
Call OpenRelay models from the Vercel AI SDK with @ai-sdk/openai-compatible, including generateText, streamText, tools, structured output and embeddings.
Pricing & billing
How inference is billed, a prepaid balance, per-token metering with distinct input, cached-input, and output rates, and the usage and cost on every response.