Skip to main content
Enabled when OPENAI_API_KEY is set in your environment.

Overview

The @standardagents/openai package provides the OpenAI provider factory for Standard Agents. It enables direct access to OpenAI models with typed providerOptions and built-in provider tools.

Key Features

  • Direct OpenAI API access with automatic client management
  • Typed providerOptions with TypeScript autocompletion
  • Built-in provider tools (web search, file search, code interpreter, image generation)
  • Model capability detection and icon support

Installation

npm
pnpm
yarn

Quick Start

agents/models/gpt_5_4.ts

Provider Factory

The openai export is a provider factory function that creates OpenAI provider instances:
Unlike the legacy string-based provider: 'openai', the new API uses an imported factory function. This enables typed providerOptions and runtime validation.

Connection Config Slots

The OpenAI factory exposes connection-level config slots that defineProvider sub-providers can override:
SlotTypeDefault
apiKeysecretOPENAI_API_KEY
baseUrlurlhttps://api.openai.com/v1
timeoutnumber30000
Use this for OpenAI-compatible providers that share request/response behavior but use a different endpoint and credential:
agents/providers/darkbloom.ts

Provider Options

The openai factory includes a typed schema for provider-specific options:

Available Options

OptionTypeDescription
service_tier'auto' | 'default' | 'flex'Service tier for request processing
userstringUser identifier for abuse monitoring
seednumberSeed for deterministic outputs (beta)
frequency_penaltynumberReduces repetition (-2.0 to 2.0)
presence_penaltynumberEncourages new topics (-2.0 to 2.0)
logprobsbooleanReturn log probabilities
top_logprobsnumberMost likely tokens to return (0-20)
storebooleanStore completion for future reference
metadataRecord<string, string>Metadata for stored completions

Type Safety

The providerOptions type is automatically inferred from the provider:

Provider Tools

OpenAI provides built-in tools that execute on OpenAI’s servers and can be used alongside your custom tools:
ToolDescriptionRequired tenvs
web_searchSearch the web for up-to-date information with citationsuserLocation (optional)
file_searchSearch uploaded files using vector embeddingsvectorStoreId (required)
code_interpreterExecute Python in a sandboxed containercontainerId (optional)
image_generationGenerate images via gpt-image-1
All current GPT-5.4 models (gpt-5.4, gpt-5.4-mini, gpt-5.4-nano) support these built-in tools. See OpenAI’s tool documentation for the current per-model compatibility matrix.

Using Provider Tools

Enable provider tools in your model definition:
Then reference them in prompts:

Tool Requirements

Some provider tools require thread environment variables (tenvs): file_search:
Provider tools are executed by OpenAI’s servers, not locally. Results come back in the API response and are recorded through Standard Agents’ generic provider-tool log path.

Model Capabilities

Set capabilities to help the framework understand what the model supports:

Environment Setup

Set your OpenAI API key as an environment variable:
.dev.vars
For Cloudflare Workers:

Example Configurations

High-Performance Model

Budget Model

Reasoning Model

Exports

Next Steps

Models

Learn about model configuration

OpenRouter

Access multiple providers via OpenRouter

Tools

Create custom tools

defineModel API

Complete API reference