Skip to main content
A drop-in LanguageModelV3 implementation that maps user messages through a transform function — no API key, no network calls, fully deterministic.

fake(transform)

Creates a fake language model conforming to the Vercel AI SDK LanguageModelV3 specification. The returned model can be passed directly to ToolLoopAgent or any AI SDK function that accepts a LanguageModel.

Parameters

The transform function receives two arguments:
  • lastMessage — the text content of the most recent user message (empty string if none)
  • prompt — the full LanguageModelV3Prompt conversation history, useful for tracking turn count or prior context

Return value

A LanguageModelV3 object with:
  • specificationVersion: "v3"
  • provider: "aixyz/fake"
  • modelId: "aixyz/fake"
  • doGenerate() and doStream() that call your transform and report zero token usage

Examples

Simple echo:
Using full prompt context:
Wiring into an agent:
app/agent.ts

Prompt

Type alias for LanguageModelV3Prompt from @ai-sdk/provider. This is an array of messages where each message has a role and content:
Use this type when you need to reference the prompt shape in your transform function or tests:

Testing with fake()

The fake model makes every test deterministic and CI-safe. Export the model from your agent file so tests can call doGenerate() directly:
app/agent.test.ts
See the Testing guide and the Fake Model Agent template for complete examples.