In short.
Build Your Own Headless Agent is an OpenRouter guide for developers adding AI automation to scripts and services, but its default tool choices enable file changes and command execution while the approval module is off. It describes a TypeScript and Bun project using @openrouter/agent, with CLI input, NDJSON events and optional HTTP or MCP entry points. Bun and an OpenRouter API key are required. The examples provide concrete integration details; costs, licensing and runtime reliability remain unknown or unassessed.
Researched and written by an AI model and checked by a second AI model. How it works
Coverage includes the complete documentation page at [https://openrouter.ai/docs/cookbook/building-agents/create-headless-agent.md]. The documentation-index notice and links to GitHub, npm, the TUI guide, SDK documentation, server tools and API-key settings are references only; linked content is excluded. No generated project files were supplied. Installation, tool execution, API calls, schema validation, retry behavior and session recovery were not exercised. No redistribution licence was provided.
The overview
identity
This OpenRouter cookbook guide explains the create-headless-agent skill, which a coding assistant uses to generate an AI agent project. Headless means the generated agent accepts input and returns results without an interactive terminal interface. Its internal model-and-tool loop uses @openrouter/agent. Source: [https://openrouter.ai/docs/cookbook/building-agents/create-headless-agent.md].
assessment
The guide is useful for developers who want a concrete starting point for integrating an agent into their own application. It documents project files, inputs, outputs and configuration choices in enough detail to explain the intended architecture. It does not establish that a generated project will meet a particular application's reliability or security requirements.
The most consequential default is the combination of enabled file and shell tools with the approval module disabled. Developers should review those choices before letting the generated agent operate on real files.
users
The intended users include developers building CLI tools, API services, queue workers, batch jobs and CI automation. It also suits developers learning how model calls and tool execution fit together. Beginners will need familiarity with a terminal, API credentials and TypeScript project files to follow the implementation details comfortably.
capabilities
The generated CLI accepts a prompt through --prompt, positional arguments or piped stdin. It can stream text, emit one AgentEvent per line as NDJSON through --json, or suppress output through --quiet. NDJSON is a sequence of JSON records, so consumers should parse it line by line.
Preselected tools include OpenRouter server-side web search, web fetch and datetime, plus local file reading, writing, editing, file discovery, content search, directory listing, shell execution and URL fetching. Session persistence and retry are preselected. Context compaction, prompt composition, approvals, structured event logging, output validation and webhooks are optional and initially off.
Using it
requirements
The stated runtime prerequisites are Bun and an OpenRouter API key. A compatible AI coding assistant is needed to use the scaffolding skill. The generated project includes @openrouter/agent and Zod; optional final-response validation uses Ajv.
The GitHub CLI installation route requires version 2.90.0 or later. The page gives no minimum Bun version, operating-system support matrix or pinned SDK version.
mechanism
During setup, the skill presents a checklist of tools and modules and generates the chosen project. At runtime, @openrouter/agent repeatedly calls a model, executes requested tools and continues until a stop condition fires. Documented controls include stepCountIs(n), maxCost(amount), hasToolCall(name) and custom conditions. Tools use Zod input schemas and execute functions; sharedContextSchema supplies typed state across tools.
The retry wrapper handles transient 429 and 5xx errors with exponential backoff only before any tool call has executed. After tool execution, it throws instead of restarting the agent from its initial prompt. This guard addresses replayed side effects; the page provides no execution evidence for its behavior.
setup
The documented GitHub CLI command is gh skill install OpenRouterTeam/skills create-headless-agent. The page also provides Claude Code marketplace commands and a Cursor remote-rule installation route. After installation, asking the coding assistant to scaffold a headless agent activates the skill and its checklist.
The resulting project separates configuration, the agent runner, the CLI and individual tools under src/. Configuration layers defaults, a file and environment values. Set OPENROUTER_API_KEY before invoking the generated CLI. An HTTP server using Bun.serve() with SSE streaming or an MCP server can be requested instead of the default CLI entry point.
example
The documented command bun run src/cli.ts --json --prompt "Search for TODO comments" illustrates a programmatic search task. It is intended to return an NDJSON event stream. This is a usage example, not an observed result.
With the Output Schema Validation module included, --output-schema report.schema.json can require a final response containing a string summary and a nonnegative integer count. The guide documents exit code 0 for success, 1 for an agent or API error and 2 for schema validation failure. Validation errors appear on stderr or as validation_error events in JSON mode.
Assessment & evidence
limitations
Approval gates and final-output schema validation require explicit selection. The page describes no filesystem sandbox or shell isolation boundary. Schema validation checks the response's structure; it does not establish the factual accuracy of its contents.
The retry guard stops automatic restart after tool execution, so a mid-run failure may require recovery. The guide suggests JSONL session persistence for continuation, but does not demonstrate crash recovery or cross-process approval behavior. Installation reliability, latency, model compatibility and production performance are unassessed.
reasoning
Programmatic input, event streams and exit codes make the described scaffold a plausible fit for application integration. Zod tool-input validation and optional Ajv final-output validation address separate boundaries: what tools receive and what the agent returns. These concrete interfaces make the guide useful, while the disabled approval default means developers must make deliberate choices about allowed actions.
alternatives
The page points to Build Your Own Agent TUI for an interactive terminal experience: [https://openrouter.ai/docs/cookbook/building-agents/create-agent-harness-tui.md]. It describes that option as using the same underlying SDK with an interactive outer layer. The linked guide was not assessed, and this page provides no substantive comparison with other frameworks or hosted agents.
evidence
The evidence consists of the complete OpenRouter documentation page, retained as selected-page.txt. It supports descriptions of intended setup, architecture, defaults and CLI behavior. It contains no benchmark results, runtime logs or inspected generated project. The scaffold and example commands were not executed. Linked repositories, package metadata and other documentation were not assessed.
Access & freshness
costs
Total cost is unknown. The page supplies no model prices, server-tool fees, free allowance or representative spending examples. An API key requirement alone does not establish a price.
The SDK exposes input and output token counts through result.getResponse().usage and offers maxCost(amount) as a stop condition. The page does not explain billing coverage or demonstrate enforcement of that condition, so it should not be treated as evidence of a guaranteed spending ceiling.
rights
The page does not state licences for the documentation, skill, SDK or generated output. Commercial-use and redistribution rights are therefore unknown from this material. Links to GitHub and npm do not establish those permissions; their licence files and terms were not included.
freshness
The page was captured on 23 November 2026 at 14:10:36.637 UTC. It supplies no publication or last-updated date and pins no Bun or @openrouter/agent version. Its GitHub CLI requirement is explicit, but compatibility with particular current releases and the implementation's maintenance history remain unknown.
actions
Before using the scaffold with real files, select only the necessary tools and consider enabling approval for file changes and shell commands. Choose a model, configure stop conditions and obtain applicable prices and licence terms.
For integration work, decide whether the consumer needs streamed events or a final response validated against a schema. Verify parsing, error handling, validation failures and recovery using disposable inputs before depending on those behaviors in an application.
