PluginBench
Skill
Official
Pass
Audit score 90

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
Prerequisites
  • Access to Vercel AI monorepo structure
  • Examples from /examples/ai-functions directory
  • pnpm package manager for running scripts
Claude Code
Cursor
Windsurf
Cline

How to use capture-api-response-test-fixture

  1. 1.For generateText: call the API, log JSON.stringify(result.response.body) to console, copy output to new fixture file
  2. 2.For streamText: set includeRawChunks to true, use saveRawChunks helper, run script via pnpm tsx from /examples/ai-functions
  3. 3.Store fixtures in __fixtures__ subfolder (e.g., packages/openai/src/responses/__fixtures__)
  4. 4.Follow naming conventions from existing provider fixture files
  5. 5.Reference test helpers in existing test files (e.g., openai-responses-language-model.test.ts)

Use cases

Good for
  • 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
Who it's for
  • 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

Where should I store test fixtures?

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.

How do I capture generateText responses?

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.

What's the process for streamText fixtures?

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.

Can I modify large provider responses?

Yes, you can trim responses that are too large as long as the modifications don't change the semantic meaning of the test data.

Where do I find naming conventions for fixtures?

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' });
});