capture-api-response-test-fixture
vercel/ai
Capture and store API response test fixtures for provider response parsing tests.
What is capture-api-response-test-fixture?
This skill provides guidance on creating and organizing test fixtures for API responses from AI providers. Use it when setting up response parsing tests to ensure your test suite validates against real provider responses.
- Store true provider responses in `__fixtures__` subfolders for reproducible testing
- Capture raw response output from generateText calls via console logging
- Record streaming responses using includeRawChunks and saveRawChunks helpers
- Organize fixtures following naming conventions from existing provider packages
- Generate test fixtures using examples from /examples/ai-functions
How to install capture-api-response-test-fixture
npx skills add null --skill capture-api-response-test-fixture- Access to Vercel AI monorepo structure
- Examples from /examples/ai-functions directory
- pnpm package manager for running scripts
How to use capture-api-response-test-fixture
- 1.For generateText: call the API, log JSON.stringify(result.response.body) to console, copy output to new fixture file
- 2.For streamText: set includeRawChunks to true, use saveRawChunks helper, run script via pnpm tsx from /examples/ai-functions
- 3.Store fixtures in __fixtures__ subfolder (e.g., packages/openai/src/responses/__fixtures__)
- 4.Follow naming conventions from existing provider fixture files
- 5.Reference test helpers in existing test files (e.g., openai-responses-language-model.test.ts)
Use cases
- Setting up response parsing tests for OpenAI or other AI providers
- Creating fixtures for generateText (doGenerate) testing workflows
- Capturing streaming response fixtures for streamText (doStream) testing
- Validating provider response handling in test suites
- Storing large API responses in organized fixture directories
- Package maintainers building AI SDK integrations
- Test engineers writing provider response parsing tests
- Developers contributing to Vercel AI framework
capture-api-response-test-fixture FAQ
Store them in a `__fixtures__` subfolder relative to the code being tested, e.g., `packages/openai/src/responses/__fixtures__`. See existing provider packages for naming conventions.
Call generateText with your model and prompt, then log the raw response with `console.log(JSON.stringify(result.response.body, null, 2))` and copy the output to a fixture file.
Set `includeRawChunks: true` in your streamText call, use the `saveRawChunks` helper, run the script via `pnpm tsx` from `/examples/ai-functions`, then copy the output file to your fixtures folder.
Yes, you can trim responses that are too large as long as the modifications don't change the semantic meaning of the test data.
Check the file names in existing provider fixture folders (e.g., `packages/openai/src/responses/__fixtures__`) and review how they're used in corresponding test files.
Full instructions (SKILL.md)
Source of truth, from vercel/ai.
name: capture-api-response-test-fixture description: Capture API response test fixture. metadata: internal: true
API Response Test Fixtures
For provider response parsing tests, we aim at storing test fixtures with the true responses from the providers (unless they are too large in which case some cutting that does not change semantics is advised).
The fixtures are stored in a __fixtures__ subfolder, e.g. packages/openai/src/responses/__fixtures__. See the file names in packages/openai/src/responses/__fixtures__ for naming conventions and packages/openai/src/responses/openai-responses-language-model.test.ts for how to set up test helpers.
You can use our examples under /examples/ai-functions to generate test fixtures.
generateText (doGenerate testing)
For generateText, log the raw response output to the console and copy it into a new test fixture.
import { openai } from '@ai-sdk/openai';
import { generateText } from 'ai';
import { run } from '../lib/run';
run(async () => {
const result = await generateText({
model: openai('gpt-5-nano'),
prompt: 'Invent a new holiday and describe its traditions.',
});
console.log(JSON.stringify(result.response.body, null, 2));
});
streamText (doStream testing)
For streamText, you need to set includeRawChunks to true and use the special saveRawChunks helper. Run the script from the /example/ai-functions folder via pnpm tsx src/stream-text/script-name.ts. The result is then stored in the /examples/ai-functions/output folder. You can copy it to your fixtures folder and rename it.
import { openai } from '@ai-sdk/openai';
import { streamText } from 'ai';
import { run } from '../lib/run';
import { saveRawChunks } from '../lib/save-raw-chunks';
run(async () => {
const result = streamText({
model: openai('gpt-5-nano'),
prompt: 'Invent a new holiday and describe its traditions.',
includeRawChunks: true,
});
await saveRawChunks({ result, filename: 'openai-gpt-5-nano' });
});
Related skills
More from vercel/ai and the wider catalog.
develop-ai-functions-example
Create and validate AI SDK function examples across providers.
list-npm-package-content
List npm package tarball contents before publishing to verify what gets uploaded.
migrate-ai-sdk-v6-to-v7
Agent skill from vercel/ai.
add-provider-package
Guide for creating new @ai-sdk/<provider> packages to integrate AI services into the Vercel AI SDK.
chat-sdk
Unified TypeScript SDK for building chat bots across Slack, Teams, Google Chat, Discord, Telegram, GitHub, Linear, WhatsApp, and more.

building-components
Guide for building modern, accessible, and composable UI components with best practices.