npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@raindrop-ai/openrouter-agent

v0.2.8

Published

Raindrop integration for the OpenRouter Agent SDK

Readme

@raindrop-ai/openrouter-agent

Raindrop integration for the OpenRouter Agent SDK (@openrouter/agent).

Installation

pnpm add @raindrop-ai/openrouter-agent @openrouter/agent

Usage

import { OpenRouter, tool } from "@openrouter/agent";
import { z } from "zod";
import { createRaindropOpenRouterAgent } from "@raindrop-ai/openrouter-agent";

const raindrop = createRaindropOpenRouterAgent({
  writeKey: process.env.RAINDROP_WRITE_KEY,
  userId: "user-123",
  convoId: "convo-456",
});

const openrouter = raindrop.wrap(
  new OpenRouter({ apiKey: process.env.OPENROUTER_API_KEY }),
);

const getWeather = tool({
  name: "get_weather",
  description: "Get the weather for a city.",
  inputSchema: z.object({ city: z.string() }),
  outputSchema: z.object({ forecast: z.string() }),
  execute: async ({ city }) => ({ forecast: `Sunny in ${city}` }),
});

const result = openrouter.callModel({
  model: "openai/gpt-4o-mini",
  input: "Use get_weather for San Francisco, then answer briefly.",
  tools: [getWeather] as const,
});

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

if (raindrop.lastEventId) {
  await raindrop.signals.track({
    eventId: raindrop.lastEventId,
    name: "thumbs_up",
    type: "feedback",
    sentiment: "POSITIVE",
  });
}

await raindrop.shutdown();

lastEventId is the last turn finished anywhere in the process; on a client shared by concurrent turns, pass your own event id with raindrop.withContext({ eventId }, ...) instead.

Standalone callModel

If you import the standalone callModel helper, wrap the function once and use the wrapped function in place of the original:

import { OpenRouter, callModel } from "@openrouter/agent";
import { createRaindropOpenRouterAgent } from "@raindrop-ai/openrouter-agent";

const raindrop = createRaindropOpenRouterAgent({
  writeKey: process.env.RAINDROP_WRITE_KEY,
  userId: "user-123",
});
const trackedCallModel = raindrop.wrapCallModel(callModel);
const openrouter = new OpenRouter({ apiKey: process.env.OPENROUTER_API_KEY });

const result = trackedCallModel(openrouter, {
  model: "openai/gpt-4o-mini",
  input: "Hello from OpenRouter",
});

await result.getText();
await raindrop.shutdown();

What Gets Captured

  • Input text from the last user message, without role prefixes
  • Output text from getText(), getResponse(), and stream consumers
  • Model name
  • Prompt, completion, cached, and total token usage when OpenRouter returns it
  • OpenRouter response status and response ID
  • Client tool calls as ai.toolCall trace spans linked to the event
  • Conversation grouping via convoId
  • Manual events, users.identify, signals.track, and traces APIs

Options

| Option | Type | Default | Description | | --- | --- | --- | --- | | writeKey | string | undefined | Optional Raindrop write key. If omitted, telemetry is disabled gracefully. | | endpoint | string | https://api.raindrop.ai/v1/ | Override the Raindrop ingest endpoint. | | debug | boolean | false | Enable debug logging for event and trace shippers. | | userId | string | undefined | Default user ID attached to captured events. | | properties | Record<string, unknown> | — | Caller properties on every captured event (merged under withContext properties) | | convoId | string | undefined | Default conversation ID attached to captured events. | | projectId | string | undefined | Route events to a specific project (slug); omit for the default Production project. | | localWorkshopUrl | string \| false \| null | auto | Force or disable local Workshop mirroring. | | events.enabled | boolean | true | Enable or disable event shipping. | | events.partialFlushMs | number | 1000 | Partial event flush interval. | | traces.enabled | boolean | true | Enable or disable trace shipping. | | traces.flushIntervalMs | number | 1000 | Trace batch flush interval. | | traces.maxBatchSize | number | 50 | Trace batch size. | | traces.maxQueueSize | number | 5000 | Maximum queued spans. | | traces.debugSpans | boolean | false | Log span parent relationships. | | maxTextFieldChars | number | 1000000 | Per-field character cap for event input/output, serialized tool args/results and custom span input/output. | | tools | PromptToolsOverride | undefined | Overrides the tool catalog recorded as ai.prompt.tools on every model span. Use when the integration cannot see the tools the model was given. | | redactPii | boolean | false | Redact PII (emails, phone numbers, card numbers, addresses, secrets) from event input/output before it leaves the process | | redactPiiFields | PiiFieldMap | - | More wire field paths to redact when redactPii is on, e.g. { event: ["properties.customer.email"] }; add properties["error.message"] to also redact error messages | | flushTimeoutMs | number | 10000 | Deadline for flush() / shutdown(). Both resolve to a result (delivered, dropped, queued, ...) and never reject |

Tool catalog capture

Every openrouter.callModel span records the tools the request carried (request.tools: tool() function tools with their zod schemas converted to JSON Schema, and serverTool()s as provider-defined) as ai.prompt.tools. Each tool is one JSON document in an OTLP string array: {"type":"function","name","description","inputSchema"} for function tools (the JSON Schema is recorded as given — properties, enums, required and per-field descriptions intact) or {"type":"provider-defined","id","name","args"} for provider-owned tools, which get no invented schema. A call without a visible tool list records no attribute; an explicit empty list records []. Pass tools to record a different catalog instead (it replaces the inferred list; tools: [] records an empty catalog).

Projects

If your org has multiple projects, route events to a specific one by passing its slug as projectId:

const raindrop = createRaindropOpenRouterAgent({
  writeKey: process.env.RAINDROP_WRITE_KEY,
  projectId: "support-prod",
});

This sets the X-Raindrop-Project-Id header on every event and trace. Omit it (or pass "default") to use your org's default Production project — the existing behavior. Single-project orgs need nothing new.

Payload size limits

Serialized tool-call args/results on trace spans (and traces.createSpan input/output) are capped at 1,000,000 characters per field by default and truncated with a ...[truncated by raindrop] marker (the result, marker included, never exceeds the limit). Serialization runs under a budget, so a multi-MB tool payload costs the cap — not the payload — on your calling thread, and oversized spans land truncated instead of being dropped at the ingest size limit. Tune it via maxTextFieldChars. Event input/output text uses the same cap (it used to be cut at 8,192 characters); there is no other client-side size limit.

Per-call context

properties on the client apply to every captured event. For one call, wrap it in raindrop.withContext(...): userId, convoId, eventName, properties and attachments apply to every event captured inside the callback, sync or async (nested calls merge; the inner value wins). Your properties win over keys the integration sets itself (ai.usage.*, error.*, ...).

const result = await raindrop.withContext(
  {
    userId: "user-123",
    properties: { tenant: "acme" },
    attachments: [{ type: "text", role: "input", name: "policy.txt", value: policyText }],
  },
  () => openrouter.callModel({ model, input }).getText(),
);

Attachments need type (text, image or iframe) and role (input or output); entries without them are dropped. Images go in as data URIs or URLs.

Known Limitations

  • Telemetry starts when a ModelResult is consumed. Creating a result without calling getText(), getResponse(), or a stream method does not ship an event.
  • Client tool spans wrap the tool's execute() / onToolCalled() function, so their timing reflects the local tool execution window.
  • Server-executed OpenRouter tools are represented from response items when available after the provider response completes. Client function tools have the richest live trace data.
  • Stream consumers that stop early still finalize a best-effort event with the text observed so far.

Testing

pnpm test

End-to-end coverage runs through the cross-SDK conformance harness. The openrouter-agent conformance driver (conformance/openrouter-agent-driver.mjs) maps the shared scenario corpus onto this package's public API. The fault lane runs locally and on every PR against a fault-injecting fake ingest; the prod lane verifies real ingest through the public Query API readback. See conformance/README.md and the harness README / HOW-IT-WORKS.

Application Git identity

Set appGit on createRaindropOpenRouterAgent to override commitSha, commitDirty, and optional ordinary branch, or pass false to opt out. The revision is unknown by default because ambient deploy/CI and observer working-directory metadata are ignored. Local Git discovery requires an explicit sourceDirectory (or RAINDROP_GIT_SOURCE_DIRECTORY); explicit RAINDROP_COMMIT_SHA values are honored. Automatic branch discovery requires detectBranch: true.