Run your first agent
Connect a model, create an agent, and stream its first answer from one small program.
Build one small program that connects your OpenRouter key, creates an agent, and streams the agent's first answer to your terminal. You add to the same file in three steps and run it after each one, so you see every piece work before you move on.
Before you begin
Finish Set up Blazing Agents and work in the same project folder and terminal. You also need an OpenRouter API key in that terminal:
export OPENROUTER_API_KEY="sk-or-..."The program is safe to run again and again. It looks up the provider and agent by name and creates them only the first time.
Connect a model provider
A provider holds the model key your agents use. Blazing Agents stores the key for you, so your program sends it only once. Create quickstart.ts or quickstart.py with this code:
import { BlazingAgents } from "@blazingagents/sdk";
const client = new BlazingAgents({
apiKey: process.env.BLAZING_AGENTS_API_KEY!,
});
const providerName = "Quickstart OpenRouter";
const { providers } = await client.providers.list();
const provider =
providers.find(({ name }) => name === providerName) ??
(await client.providers.create({
name: providerName,
providerType: "openrouter",
baseUrl: null,
apiKey: process.env.OPENROUTER_API_KEY!,
}));
console.log(`Provider: ${provider.id}`);Run it with node quickstart.ts or python quickstart.py. You see Provider: prv_..., and the same ID on every later run.
Create an agent
An agent pairs a provider with a model. Add this to the end of the file:
const agentName = "Quickstart agent";
const { agents } = await client.agents.list();
const agent =
agents.find(({ name }) => name === agentName) ??
(await client.agents.create({
name: agentName,
providerId: provider.id,
model: "openai/gpt-6-luna",
}));
console.log(`Agent: ${agent.id}`);Run the file again. You see the same Provider: prv_... line, then Agent: ag_....
Blazing Agents checks the model against your provider when you create the agent. If you get model_not_found, pick another ID from client.providers.listModels({ providerId }) in TypeScript or client.providers.list_models(provider_id=...) in Python. The first step stores your OpenRouter key without checking it, so a wrong or invalid key shows up here as model_validation_unavailable. Fix OPENROUTER_API_KEY, delete the "Quickstart OpenRouter" provider with client.providers.delete({ providerId }) in TypeScript, client.providers.delete(provider_id) in Python, or the Delete action on the dashboard's providers page, then run the file again to recreate it with the new key.
Stream the first answer
Send the agent a message and print the answer as it arrives. Add this to the end of the file:
const result = await client.chat({
agentId: agent.id,
message: {
id: crypto.randomUUID(),
role: "user",
parts: [{ type: "text", text: "Say hello in one short sentence." }],
},
});
console.log(`Session: ${await result.sessionId}`);
for await (const chunk of result.toStream()) {
process.stdout.write(chunk);
}
// The stream is yours now: relay it to your app, parse it, or store it.Run the file once more. After the IDs, the raw stream prints as it arrives:
Provider: prv_...
Agent: ag_...
Session: ss_...
data: {"type":"start",...}
data: {"type":"text-delta","id":"...","delta":"Hello"}
data: {"type":"text-delta","id":"...","delta":"!"}
...
data: [DONE]These lines are AI SDK UI message events. In a web app your backend returns result.toResponse(), and the AI SDK useChat hook renders them as chat messages. Each run starts a new session, so you see a new ss_... ID every time.
What happened
client.chat() without a sessionId starts a new session, a conversation that Blazing Agents keeps for you. You get the session ID before the answer finishes streaming, so you can save it right away. Pass it back as sessionId (session_id in Python) on the next call and the agent sees the whole conversation so far.
The answer arrives as a stream of server-sent events in the AI SDK UI message format, and the program prints them untouched. The stream is yours: relay it to your app, parse it, or store it. In a web app, return result.toResponse() from your backend and the AI SDK useChat hook renders it for you.
Next
- Connect Blazing Agents to your app to put a chat endpoint behind your own sign-in.
- Examples for complete Next.js, TanStack Start, Vite + Hono, Express, and FastAPI apps.
- Sessions and turns to continue, stop, and reload conversations.