BroadRouter

Run smolagents on BroadNet Inference with OpenAIModel

Updated

Create smolagents' OpenAIModel with model_id set to a BroadNet ID such as broadnet/glm-5.3, api_base set to https://inference.broadnet.ai/v1 and api_key set to your BroadNet key, then pass it to CodeAgent or ToolCallingAgent. CodeAgent writes Python instead of native tool calls, so it can run on DeepSeek V4.1 Flash. ToolCallingAgent needs GLM 5.3 or Qwen3.8 27B.

smolagents is Hugging Face’s small Python library for agents. Its OpenAIModel class “connects to an OpenAI-compatible API server”, with api_base for the URL. BroadNet Inference serves chat completions at https://inference.broadnet.ai/v1, so it works directly. BroadRouter is BroadNet’s own site; this follows the smolagents 1.26.0 docs.

Install

pip install smolagents
export BROADNET_API_KEY='your-broadnet-key'

CodeAgent

import os
from smolagents import OpenAIModel, CodeAgent

model = OpenAIModel(
    model_id="broadnet/deepseek-v4.1-flash",
    api_base="https://inference.broadnet.ai/v1",
    api_key=os.environ["BROADNET_API_KEY"],
    max_tokens=4000,
)

agent = CodeAgent(tools=[], model=model)
print(agent.run("What is 6 * 7? Use Python to check."))

CodeAgent asks the model to write Python between <code> tags and runs it locally. The request is a plain chat completion with stop sequences such as </code>, and no tools field. That means it doesn’t depend on native tool calling, so it can run on broadnet/deepseek-v4.1-flash, the model on BroadNet’s unlimited plans. Code quality still varies by model, so test your own tasks.

CodeAgent runs code the model writes. Read smolagents’ guidance on secure code execution before you give it tools that touch files, networks or credentials.

ToolCallingAgent

from smolagents import ToolCallingAgent, tool

@tool
def get_weather(city: str) -> str:
    """Get the weather for a city.

    Args:
        city: The city name.
    """
    return f"21C in {city}"

model = OpenAIModel(
    model_id="broadnet/glm-5.3",
    api_base="https://inference.broadnet.ai/v1",
    api_key=os.environ["BROADNET_API_KEY"],
    max_tokens=4000,
)
agent = ToolCallingAgent(tools=[get_weather], model=model)
print(agent.run("What's the weather in Riyadh?"))

ToolCallingAgent sends your tools, plus its own final_answer tool, as function schemas with tool_choice: "required". Use broadnet/glm-5.3 or broadnet/qwen3.8-27b; BroadNet’s docs list tools for these two models only.

Which model to pick

Agent Model
CodeAgent, long runs on a flat-price plan broadnet/deepseek-v4.1-flash
ToolCallingAgent broadnet/glm-5.3
Either agent with image input broadnet/qwen3.8-27b

A plan session runs one request at a time, and an agent sends its steps one after another, so one session fits one agent. Prices for every model.

How we tested this

On 2026-11-15 we installed smolagents 1.26.0 in a clean virtual environment and ran both agents against a local mock server that speaks BroadNet’s chat-completions shape. The CodeAgent on the DeepSeek ID received a code reply, ran it and returned 42. Its requests had max_tokens: 4000, stop sequences and no tools. For the ToolCallingAgent, we checked the request shape: the model ID was sent unchanged, with both tool schemas and tool_choice: "required". smolagents sends tool results back as user messages. Our mock didn’t follow that format, so we didn’t run that agent to a final answer. We had no BroadNet key, so we did not test real model output.

Troubleshooting

  • 401. The key is wrong, expired or out of allowance.
  • 404. api_base must end in /v1. Check the model ID. Paid models need a top-up; the $5 credit covers only broadnet/gemma-4-26b-a4b and the two Transcribe models.
  • “Make sure to provide correct code blobs”. The model’s reply had no code block. Raise max_tokens, because reasoning counts toward it, or try another model. Why answers come back empty.
  • ToolCallingAgent never finishes. Switch to broadnet/glm-5.3 or broadnet/qwen3.8-27b.
  • 429. A pay-as-you-go key allows 30 requests a minute. smolagents can throttle itself with requests_per_minute. See errors and retries.

Questions

Is it OpenAIModel or OpenAIServerModel?

smolagents 1.26 documents OpenAIModel for any OpenAI-compatible server. OpenAIServerModel is still exported by the package, but the docs describe OpenAIModel.

Can smolagents run on the BroadNet unlimited plan?

The plans cover DeepSeek V4.1 Flash. BroadNet doesn't list tool calling for it, but CodeAgent doesn't need native tool calls; it asks the model for Python code. In our mock test a CodeAgent on the DeepSeek ID sent plain chat requests with no tools field.

Why does ToolCallingAgent need GLM 5.3 or Qwen3.8 27B?

It sends the tools as OpenAI function schemas with tool_choice set to required. BroadNet's docs list tools for GLM 5.3 and Qwen3.8 27B only.

How do I pass max_tokens or temperature?

As keyword arguments to OpenAIModel. smolagents' docs say extra arguments are forwarded to every completion call. In our test max_tokens=4000 was sent on each request.

Read as MarkdownAsk ChatGPTAsk ClaudeAsk Perplexity