Skip to main content

Getting Started with OpenRouter

OpenBox integrates with the OpenRouter Agent SDK by wrapping callModel and your tools. Your agent stays as it is; OpenBox adds policy evaluation before each call runs, approvals, telemetry, and Proof of Routing — the record of which upstream provider actually served each prompt.

Install

npm install openbox-openrouter-governance @openrouter/agent

Node 18.17 or later. @openrouter/agent is a peer dependency.

Two Wrapped Calls

src/agent.ts
import { OpenRouter, callModel, tool } from '@openrouter/agent';
import { createOpenBoxGovernance } from 'openbox-openrouter-governance';

const client = new OpenRouter({ apiKey: process.env.OPENROUTER_API_KEY });

const openbox = createOpenBoxGovernance({ agentName: 'research-agent' });

const tools = openbox.tools([myTool]);

const result = await openbox.callModel(callModel, client, {
model: 'anthropic/claude-sonnet-5',
input: 'Summarize the latest incident report',
tools,
});

console.log(await result.getText());

await openbox.close();

openbox.tools() governs each tool end to end — evaluated before it runs, held open across a human approval, recorded when it finishes. openbox.callModel() governs the model call and returns OpenRouter's own result untouched, so getText(), getTextStream() and every other consumption pattern keep working.

Always await openbox.close(). It drains in-flight telemetry and the routing records that arrive just after the last answer.

Environment

OPENBOX_API_KEY=obx_...
OPENBOX_API_URL=https://core.openbox.ai
OPENBOX_AGENT_DID=did:aip:...
OPENBOX_AGENT_PRIVATE_KEY=...
OPENROUTER_API_KEY=sk-or-...

OPENROUTER_API_KEY does double duty: your agent calls the gateway with it, and the SDK reads each call's generation record back with it. Without a key, routing provenance is inert and the rest of governance is unaffected.

Register the Agent as OpenRouter

In the dashboard, choose OpenRouter as the framework when registering the agent.

This matters more than it looks. The Provenance tab and every routing figure are scoped to agents on this framework, because the record only exists for gateway-routed calls. An agent that genuinely routes through OpenRouter but is registered as something else will show nothing until the framework is corrected.

What You Get

Where to look
Every model call and tool evaluated before it runsMonitor
Which provider served each prompt, in which region, at what costRouting Integrity
A provider allowlist the gateway fails closed onRouting Policies
Signed evidence you can hand to a customerRun Receipt

Next Steps

  1. Run the Demo - Four real calls that produce every routing outcome
  2. SDK Reference - The full API surface
  3. Routing Policies - Constrain where prompts may go
  4. Proof of Routing - Why the record exists and what it can prove