Index of every page on this site: llms.txt
All skills
vercel avatar

/capture-api-response-test-fixture

@a8f0e9d official
by vercelvercel/ai28k stars
5,666
Run it yourself

Capture API response test fixture.

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

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

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

How this Skill uses context

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈70 characters, or 0.9%.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

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 rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts7mo5 checks · Risk SAFE
  • Gen Agent Trust Hub8mo

    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.

  • Socket8mo

    No alerts

  • Snyk8mo

    Risk: LOW · No issues

  • Runlayer9mo

    1/1 file flagged

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

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

Last checked against GitHub yesterday.

Activeupdated 3 months ago
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.