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 defaultconst 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)from toolnexus import create_toolkit, create_client
tk = await create_toolkit() # 10 built-ins, on by defaultagent = create_client( base_url="https://openrouter.ai/api/v1", style="openai", model="openai/gpt-4o-mini",)res = await agent.run("List the files here, then read the largest one.", tk)print(res.text)ctx := context.Background()tk, _ := toolnexus.CreateToolkit(ctx, toolnexus.Options{}) // 10 built-insagent := toolnexus.CreateClient(toolnexus.ClientOptions{ BaseURL: "https://openrouter.ai/api/v1", Style: toolnexus.StyleOpenAI, Model: "openai/gpt-4o-mini", APIKey: os.Getenv("OPENROUTER_API_KEY"),})res, _ := agent.Run(ctx, "List the files here, then read the largest one.", tk)fmt.Println(res.Text)Toolkit tk = Toolkit.create(new Toolkit.Options()); // 10 built-ins, on by defaultLlmClient agent = LlmClient.create(new LlmClient.Options() .baseUrl("https://openrouter.ai/api/v1") .style("openai") .model("openai/gpt-4o-mini"));System.out.println(agent.run("List the files here, then read the largest one.", tk).text);await using var tk = await Toolkit.CreateAsync(new Toolkit.Options()); // 10 built-insvar agent = LlmClient.Create(new LlmClient.Options { BaseUrl = "https://openrouter.ai/api/v1", Style = "openai", Model = "openai/gpt-4o-mini",});var res = await agent.RunAsync("List the files here, then read the largest one.", tk);Console.WriteLine(res.Text);{:ok, tk} = Toolnexus.create_toolkit() # 10 built-ins, on by defaultclient = Toolnexus.Client.create( base_url: "https://openrouter.ai/api/v1", style: "openai", model: "openai/gpt-4o-mini", api_key: System.get_env("OPENROUTER_API_KEY"))res = Toolnexus.Client.run(client, "List the files here, then read the largest one.", tk)IO.puts(res.text)(require '[toolnexus.core :as tn] '[toolnexus.client :as client])
(def tk (tn/build {:builtins true})) ; 10 built-ins, on by default(def agent (client/create-client {:base-url "https://openrouter.ai/api/v1" :style "openai" :model "openai/gpt-4o-mini"})) ; api-key from OPENROUTER_API_KEY(def res (client/run agent "List the files here, then read the largest one." {:toolkit tk}))(println (:text res))use toolnexus::client::{ClientOptions, Style, create_client};use toolnexus::{ToolkitOptions, create_toolkit};
#[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> { let tk = create_toolkit(ToolkitOptions::default()).await?; // 10 built-ins, on by default let names: Vec<String> = tk.tools().into_iter().map(|t| t.name).collect(); assert!(names.iter().any(|n| n == "bash") && names.iter().any(|n| n == "read")); println!("tools: {}", names.join(" "));
if std::env::var("OPENROUTER_API_KEY").is_err() { println!("skip: OPENROUTER_API_KEY not set"); return Ok(()); } let agent = create_client(ClientOptions { base_url: "https://openrouter.ai/api/v1".into(), style: Style::OpenAI, model: "openai/gpt-4o-mini".into(), // key from OPENROUTER_API_KEY ..Default::default() }); let res = agent.run("List the files here, then read the largest one.", &tk).await?; println!("{}", res.text); Ok(())}Next: MCP servers.