Documentation Index
Fetch the complete documentation index at: https://mintlify.com/visible/cruel/llms.txt
Use this file to discover all available pages before exploring further.
Overview
cruelModel() wraps an AI SDK v3 language model to inject realistic failure scenarios and performance issues. Use it to test how your application handles AI errors, delays, and edge cases.
Function Signature
The AI SDK v3 language model to wrap. This can be any model from providers like OpenAI, Anthropic, Google, etc.
Chaos configuration options. See Chaos Options below.
Returns
Returns a wrapped model with the same type signature as the input model. The wrapped model interceptsdoGenerate() and doStream() calls to inject chaos before and during generation.
Chaos Options
All options accept probability values between 0 and 1 (e.g.,0.1 = 10% chance).
Error Simulation
Probability of throwing an invalid API key error (401)
Probability of throwing a quota exceeded error (429)
Probability of throwing a model unavailable error (404)
Probability of throwing a context length exceeded error (400)
Probability of throwing a content filter violation error (400)
Probability of throwing an empty response error
Probability of throwing a generic API failure (500)
Probability of hanging indefinitely (simulates network timeout)
Probability of throwing a rate limit error (429). Can specify
retryAfter in seconds (default: 60)Probability of throwing a server overloaded error (503)
Performance Issues
Add artificial delay before request in milliseconds. Can be a fixed value or
[min, max] rangeAdd delay between each token in streaming responses (milliseconds)
Streaming Issues
Probability of abruptly cutting the stream mid-response
Probability of corrupting individual stream chunks by injecting replacement characters
Response Manipulation
Probability of truncating response text (returns 10-70% of content)
Override the finish reason in the response. When set, always replaces the actual finish reason
Override token usage counts in the response
Observability
Callback invoked whenever chaos is injected. Useful for logging, metrics, and testing
Examples
Basic Error Testing
Testing Stream Failures
Production-Like Testing with Observability
Simulating Token Counting Issues
Integration with AI SDK
The wrapped model works seamlessly with all AI SDK functions:Chaos Events
WhenonChaos is provided, it receives events with these types:
Related Functions
- cruelProvider() - Wrap an entire provider instead of individual models
- cruelMiddleware() - Apply chaos as AI SDK middleware
- presets - Pre-configured chaos scenarios