All skills
vercel avatar

/capture-api-response-test-fixture

@0f25f5d official
by vercelvercel/ai27k stars
5,232

Capture API response test fixture.

Use this Skill: https://skilld.dev/gh/vercel/ai/capture-api-response-test-fixture

This session only. Nothing lands on disk.

SKILL.md

≈17 tokens always: the name and description. ≈510 when used: this file.

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, put the script under src/generate-text/<provider>/, 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. Put the script under the provider directory and run it from the /examples/ai-functions folder via pnpm tsx src/stream-text/<provider>/<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' });
});

Source: SKILL.md on GitHub

No alerts5mo5 checks · Risk SAFE
  • Gen Agent Trust Hub7mo

    This skill provides instructions and utility code for generating API response test fixtures. It facilitates the capture of raw model responses for local testing and does not exhibit any suspicious or dangerous patterns.

  • Socket6mo

    No alerts

  • Snyk7mo

    Risk: LOW · No issues

  • Runlayer7mo

    1/1 file flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 0f25f5d. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 10 hours ago.

Activeupdated last month
metadata
{
  "internal": true
}

README badge

README badge for vercel/ai/capture-api-response-test-fixture

Captures raw API responses from AI providers like OpenAI for use as test fixtures in the Vercel AI SDK. Provides helpers and conventions for storing provider responses in `__fixtures__` folders and testing response parsing for both `generateText` and `streamText` functions.

Generated from the current SKILL.md.

How do I capture fixtures for generateText?
Log the raw response output to the console using JSON.stringify(result.response.body, null, 2) and copy it into a new test fixture file in the __fixtures__ subfolder.
How do I capture fixtures for streamText?
Set includeRawChunks to true and use the saveRawChunks helper, then run the script from /examples/ai-functions via pnpm tsx. The output is saved to /examples/ai-functions/output and can be copied to your fixtures folder.
Where should test fixtures be stored?
Store fixtures in a __fixtures__ subfolder within the package, e.g. packages/openai/src/responses/__fixtures__, following the naming conventions in that directory.
Can I use partial or truncated API responses as fixtures?
Yes. True provider responses are preferred, but cutting down fixtures is acceptable as long as the semantics are not changed.

Generated from the current SKILL.md. These answers refresh after source changes.