Skip to content

Zero to agent

The three-liner: a toolkit with the ten built-in tools, a client pointed at any OpenAI- or Anthropic-style endpoint, and one run. With no apiKey, the key is read only from the env var that belongs to the baseUrl host (openrouter.ai → OPENROUTER_API_KEY, api.openai.com → OPENAI_API_KEY, api.anthropic.com → ANTHROPIC_API_KEY, https only) and never printed. Any other host needs apiKey or apiKeyEnv — see API key by host.

import { createToolkit, createClient } from "toolnexus"
const tk = await createToolkit() // 10 built-ins, on by default
const agent = createClient({
baseUrl: "https://openrouter.ai/api/v1", style: "openai",
model: "openai/gpt-4o-mini", apiKey: process.env.OPENROUTER_API_KEY,
})
const res = await agent.run("List the files here, then read the largest one.", tk)
console.log(res.text)

Next: MCP servers.