experimental_getRealtimeToolDefinitions()
experimental_getRealtimeToolDefinitions is part of the experimental realtime
API.
Converts an AI SDK ToolSet into provider-neutral realtime tool definitions
that can be passed to a realtime session setup request.
Use it in the server-side setup endpoint that creates a short-lived realtime provider token.
import { openai } from '@ai-sdk/openai';import { experimental_getRealtimeToolDefinitions, tool } from 'ai';import { z } from 'zod';
const tools = { getWeather: tool({ description: 'Get the current weather for a city', inputSchema: z.object({ city: z.string(), }), }),};
const toolDefinitions = await experimental_getRealtimeToolDefinitions({ tools,});
const token = await openai.experimental_realtime.getToken({ model: 'gpt-realtime', sessionConfig: { tools: toolDefinitions, },});Import
import { experimental_getRealtimeToolDefinitions } from "ai"API Signature
Parameters
options:
Object
Object
tools:
ToolSet
toolsContext?:
InferToolSetContext<TOOLS>
Returns
A Promise<Experimental_RealtimeToolDefinition[]>.
Each returned definition contains:
type:
'function'
name:
string
description:
string | undefined
parameters:
JSONSchema7
Notes
- Tool execution is not handled by
experimental_getRealtimeToolDefinitions. Useexperimental_useRealtimeonToolCallandaddToolOutputto execute tools and return results. - Provider tools are skipped because realtime providers expect regular function definitions in the session config.
- Dynamic tool descriptions are resolved with the matching value from
toolsContextbefore the definitions are returned.