Ship resilient AI and APIs.

Inject realistic failures into AI SDK flows and core async APIs before launch.

session 2: core
seed 77
stable
import { cruel } from "cruel"
const api = cruel(fetch, {
fail: 0.1,
delay: [120, 900],
timeout: 0.05,
})
 
const res = await api("https://api.example.com")
request chaos injected

Chaos presets that feel like production.

Cruel gives you realistic failure timing, not just random errors. Use presets for quick coverage, then tune per-model and per-api options when you need precision.

  • realistic / unstable / harsh / nightmare / apocalypse
  • deterministic seeds for reproducible failures
  • hook into every chaos event via onChaos
$ bun add cruel ai @ai-sdk/openai
import { openai } from "@ai-sdk/openai"
import { generateText } from "ai"
import { cruelModel, presets } from "cruel/ai-sdk"
 
const model = cruelModel(openai("gpt-4o"), {
...presets.nightmare,
timeout: 0.2,
})

Streaming chaos you can actually test.

Streaming fails differently. Cruel can slow tokens, corrupt deltas, and cut streams mid-flight to prove your UI and service retry logic are solid.

  • slowTokens (typing under pressure)
  • corruptChunks (bad deltas, weird bytes)
  • streamCut (mid-transfer termination)
const model = cruelModel(openai("gpt-4o"), {
slowTokens: [40, 120],
corruptChunks: 0.03,
streamCut: 0.05,
})
 
const result = streamText({ model, prompt })
for await (const part of result.fullStream) {
consume(part)
}

Diagnostics your team can ship with.

Track chaos events per request, measure latency distribution, and spot resilience gaps with a clean timeline. Cruel helps you fix real bugs in models and services.

  • group events by request id
  • compute p50/p95/p99 latency
  • count retries and failures accurately
import { cruelModel } from "cruel/ai-sdk"
const events = [] as string[]
const model = cruelModel(openai('gpt-4o'), {
onChaos: (event) => events.push(event.type),
})
 
await generateText({ model, prompt })
const counts = events.reduce(group, {})
console.log(counts)

Chaos infrastructure that ships.

We focus on production-grade failure simulation for AI apps and async backends, not synthetic demos.

001

Chaos presets

Start from realistic presets, then tune options per provider, model, or API.

002

Core and AI SDK

Wrap fetch and async functions with cruel(...), or wrap providers and models with cruel/ai-sdk.

003

Stream drills

Test slow tokens, chunk corruption, and stream cuts before shipping UI.

004

CI replay

Seed chaos once and replay deterministic sequences in every pipeline.