Skip to content

FunctionModel

Callback-based mock model for complex test scenarios. Implements LanguageModelV3.

Delegates every model call to a user-supplied function that receives the full message context and can return any response — text, tool calls, or errors.

const model = new FunctionModel((messages, { callIndex }) => {
if (callIndex === 0) return { toolCalls: [...], usage: ..., finishReason: "tool-calls" }
return { text: "Done!", usage: ..., finishReason: "stop" }
})
  • LanguageModelV3

new FunctionModel(handler): FunctionModel

FunctionModelHandler

FunctionModel

readonly modelId: "function-model" = "function-model"

Provider-specific model ID.

LanguageModelV3.modelId


readonly provider: "function" = "function"

Provider ID.

LanguageModelV3.provider


readonly specificationVersion: "v3"

The language model must specify which language model interface version it implements.

LanguageModelV3.specificationVersion


readonly supportedUrls: object = {}

Supported URL patterns by media type for the provider.

The keys are media type patterns or full media types (e.g. */* for everything, audio/*, video/*, or application/pdf). and the values are arrays of regular expressions that match the URL paths.

The matching should be against lower-case URLs.

Matched URLs are supported natively by the model and are not downloaded.

A map of supported URL patterns by media type (as a promise or a plain object).

LanguageModelV3.supportedUrls

doGenerate(options): Promise<LanguageModelV3GenerateResult>

Generates a language model output (non-streaming).

Naming: “do” prefix to prevent accidental direct usage of the method by the user.

LanguageModelV3CallOptions

Promise<LanguageModelV3GenerateResult>

LanguageModelV3.doGenerate


doStream(): Promise<never>

Generates a language model output (streaming).

Naming: “do” prefix to prevent accidental direct usage of the method by the user.

Promise<never>

A stream of higher-level language model output parts.

LanguageModelV3.doStream


reset(): void

Reset call index for reuse across tests.

void