Skip to content
OpenRelay is in early access, and the /v1 API is stable. New capabilities ship in the changelog.
Skip to Content
GuidesInference

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-pro and openrelay/deepseek-v4.1-flash reason by default. reasoning_effort takes none (off), low, high or max.
  • openrelay/glm-5.3-flash always reasons; reasoning_effort has no effect.
  • openrelay/gemma-4-31b does not reason by default. Set reasoning_effort to low, high or max to 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_usage in Python, result.metrics.accumulatedUsage in 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-pro rejects frequency_penalty and presence_penalty with a 400, so leave them unset for that model.

On this page