stubfetch

Deterministic, in-process fake HTTP APIs for testing agents and tools. Swap live network calls for canned GitHub, Stripe, OpenAI, Anthropic, S3, and Slack responses — while recording traffic, running eval scenarios, and injecting chaos.

Install

npm install stubfetch

Requires Node.js 18+. No runtime dependencies.

Quick start

import { GhostEnv, github, exportRecordingJSON } from "stubfetch";

const env = new GhostEnv({
  seed: 42,
  providers: [github({ issues: [{ repo: "acme/api", title: "Bug #1" }] })],
});

const res = await env.fetch("https://api.github.com/repos/acme/api/issues");
const issues = await res.json();
console.log(issues[0].title); // "Bug #1"

// Inspect call history
console.log(env.wasCalled("github")); // true
console.log(exportRecordingJSON(env.calls()));

Presets

PresetImportURLs handled
GitHubgithub()api.github.com issues, repos, PRs
Stripestripe()api.stripe.com customers, charges
OpenAIopenai()api.openai.com chat completions
Anthropicanthropic()api.anthropic.com messages
S3s3()s3.amazonaws.com GET, list, put
Slackslack()slack.com/api auth, messages
Postgresdb()In-process db().query()

Chaos injection

const env = new GhostEnv({
  seed: 0,
  providers: [github()],
  chaos: { minLatencyMs: 50, failureRate: 0.1 },
});

Guides

DocContents
OverviewProduct summary and sidebar
Getting startedProviders, fetch, recording (Python: fetch(status, body))
Use casesStubs, fixtures, evals
PresetsURLs, config shapes, matching rules
API referenceGhostEnv, Provider, eval, replay, exports
Testing & chaosrunEval / run_eval, chaos, failure recording
Python packageNode vs Python differences