Variable: tools
@providerprotocol/ai / openai / tools
Variable: tools
Section titled “Variable: tools”
consttools:object
Defined in: src/providers/openai/types.ts:1558
Namespace object containing all tool helper constructors.
Provides a convenient way to create built-in tool configurations for the Responses API.
Type Declaration
Section titled “Type Declaration”codeInterpreter()
Section titled “codeInterpreter()”codeInterpreter: (
options?) =>OpenAICodeInterpreterTool=codeInterpreterTool
Creates a code interpreter tool configuration
Creates a code interpreter tool configuration for the Responses API.
The code interpreter tool allows the model to write and execute Python code in a sandboxed environment.
Parameters
Section titled “Parameters”options?
Section titled “options?”Optional container configuration
container?
Section titled “container?”string | OpenAICodeInterpreterContainer
Returns
Section titled “Returns”A code interpreter tool configuration object
Example
Section titled “Example”// Default configurationconst interpreter = codeInterpreterTool();
// With custom container settingsconst customInterpreter = codeInterpreterTool({ container: { type: 'auto', memory_limit: '4g', file_ids: ['file_abc123'] }});computer()
Section titled “computer()”computer: (
options) =>OpenAIComputerTool=computerTool
Creates a computer tool configuration
Creates a computer tool configuration for the Responses API.
The computer tool enables the model to interact with computer interfaces through mouse and keyboard actions.
Parameters
Section titled “Parameters”options
Section titled “options”Display configuration and environment settings
display_height
Section titled “display_height”number
display_width
Section titled “display_width”number
environment?
Section titled “environment?”Returns
Section titled “Returns”A computer tool configuration object
Example
Section titled “Example”const computer = computerTool({ display_width: 1920, display_height: 1080, environment: { type: 'browser' }});fileSearch()
Section titled “fileSearch()”fileSearch: (
options) =>OpenAIFileSearchTool=fileSearchTool
Creates a file search tool configuration
Creates a file search tool configuration for the Responses API.
The file search tool enables the model to search through files in vector stores.
Parameters
Section titled “Parameters”options
Section titled “options”Configuration including vector store IDs and search options
filters?
Section titled “filters?”Record<string, unknown>
max_num_results?
Section titled “max_num_results?”number
ranking_options?
Section titled “ranking_options?”{ ranker?: "auto" | "default_2024_08_21"; score_threshold?: number; }
ranking_options.ranker?
Section titled “ranking_options.ranker?”"auto" | "default_2024_08_21"
ranking_options.score_threshold?
Section titled “ranking_options.score_threshold?”number
vector_store_ids
Section titled “vector_store_ids”string[]
Returns
Section titled “Returns”A file search tool configuration object
Example
Section titled “Example”const fileSearch = fileSearchTool({ vector_store_ids: ['vs_abc123'], max_num_results: 10});imageGeneration()
Section titled “imageGeneration()”imageGeneration: (
options?) =>OpenAIImageGenerationTool=imageGenerationTool
Creates an image generation tool configuration
Creates an image generation tool configuration for the Responses API.
The image generation tool allows the model to generate images based on prompts.
Parameters
Section titled “Parameters”options?
Section titled “options?”Optional image generation settings
background?
Section titled “background?”"auto" | "transparent" | "opaque"
model?
Section titled “model?”string
output_format?
Section titled “output_format?”"jpeg" | "png" | "webp"
partial_images?
Section titled “partial_images?”number
quality?
Section titled “quality?”"auto" | "low" | "medium" | "high"
"auto" | "1024x1024" | "1024x1536" | "1536x1024"
Returns
Section titled “Returns”An image generation tool configuration object
Example
Section titled “Example”// Default configurationconst imageGen = imageGenerationTool();
// With custom settingsconst customImageGen = imageGenerationTool({ quality: 'high', size: '1024x1024', background: 'transparent'});mcp: (
options) =>OpenAIMcpTool=mcpTool
Creates an MCP tool configuration
Creates an MCP (Model Context Protocol) tool configuration for the Responses API.
The MCP tool enables connections to external MCP servers, allowing the model to use tools and resources provided by those servers.
Parameters
Section titled “Parameters”options
Section titled “options”MCP server configuration
allowed_tools?
Section titled “allowed_tools?”string[] | { type: "all"; }
headers?
Section titled “headers?”Record<string, string>
string
require_approval?
Section titled “require_approval?”"always" | "never" | { tools: string[]; type: "except"; }
string
Returns
Section titled “Returns”An MCP tool configuration object
Example
Section titled “Example”const mcp = mcpTool({ url: 'https://mcp-server.example.com', name: 'my-mcp-server', allowed_tools: ['tool1', 'tool2']});webSearch()
Section titled “webSearch()”webSearch: (
options?) =>OpenAIWebSearchTool=webSearchTool
Creates a web search tool configuration
Creates a web search tool configuration for the Responses API.
The web search tool enables the model to search the web for up-to-date information.
Parameters
Section titled “Parameters”options?
Section titled “options?”Optional configuration for search behavior and user location
search_context_size?
Section titled “search_context_size?”"low" | "medium" | "high"
user_location?
Section titled “user_location?”OpenAIWebSearchUserLocation | null
Returns
Section titled “Returns”A web search tool configuration object
Example
Section titled “Example”// Basic web searchconst search = webSearchTool();
// With configurationconst searchWithLocation = webSearchTool({ search_context_size: 'high', user_location: { type: 'approximate', city: 'San Francisco', country: 'US' }});Example
Section titled “Example”import { tools } from './types';
const params = { tools: [ tools.webSearch(), tools.imageGeneration({ quality: 'high' }), tools.codeInterpreter() ]};