OpenAiLanguageModel.ts
OpenAiLanguageModel.ts overview
Section titled “OpenAiLanguageModel.ts overview”The OpenAiLanguageModel module provides the OpenAI Responses API
implementation of Effect AI’s LanguageModel service. It translates Effect
AI prompts, files, tools, structured output requests, reasoning metadata, and
provider options into OpenAI response requests, then converts OpenAI
non-streaming or streaming response results back into Effect AI response
content and metadata.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”configuration
Section titled “configuration”withConfigOverride
Section titled “withConfigOverride”Provides scoped config overrides for OpenAI language model operations.
When to use
Use to apply OpenAI Responses API config overrides around one or more
language model operations without changing the defaults passed to model,
make, or layer.
Details
The override is dual, so it can be used in pipe form or as
withConfigOverride(effect, overrides). Overrides are merged with any
existing Config service in the current context, and the override values take
precedence.
See
Configfor the scoped configuration service consumed by this function
Signature
declare const withConfigOverride: { (overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>> <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>}Since v4.0.0
constructors
Section titled “constructors”Creates an OpenAI LanguageModel service from a model identifier and
optional request defaults.
When to use
Use to construct an OpenAI Responses API language model service backed by
OpenAiClient.
Details
The returned effect requires OpenAiClient. Request defaults from the
config option are merged with any Config service in the context, with
context values taking precedence. The service supports both generateText
and streamText.
See
layerfor providing the service as aLayermodelfor creating a model descriptor forEffect.provide
Signature
declare const make: (args_0: { readonly model: (string & {}) | Model readonly config?: Omit<typeof Config.Service, "model"> | undefined}) => Effect.Effect<LanguageModel.Service, never, OpenAiClient>Since v4.0.0
Creates an OpenAI model descriptor that can be provided with
Effect.provide.
When to use
Use when you want an OpenAI language model value that carries provider and model metadata and can be supplied directly to an Effect program.
See
layerfor creating aLanguageModel.LanguageModellayer directlymakefor constructing the language model service effectfully
Signature
declare const model: ( model: (string & {}) | Model, config?: Omit<typeof Config.Service, "model">) => AiModel.Model<"openai", LanguageModel.LanguageModel, OpenAiClient>Since v4.0.0
layers
Section titled “layers”Creates a layer that provides the OpenAI LanguageModel.LanguageModel
service.
When to use
Use when composing application layers and you want OpenAI to satisfy
LanguageModel.LanguageModel while supplying OpenAiClient from another
layer.
Details
The config option supplies request defaults for the selected model. Scoped
values from withConfigOverride are merged when each request is built and
take precedence over these defaults.
See
makefor constructing the language model service effectfullymodelfor creating a model descriptor forEffect.providewithConfigOverridefor scoped request configuration overrides
Signature
declare const layer: (options: { readonly model: (string & {}) | Model readonly config?: Omit<typeof Config.Service, "model"> | undefined}) => Layer.Layer<LanguageModel.LanguageModel, never, OpenAiClient>Since v4.0.0
models
Section titled “models”Model (type alias)
Section titled “Model (type alias)”OpenAI model identifiers supported by the Responses API language model.
Signature
type Model = typeof ResponseModelIds.Encoded | typeof SharedModelIds.EncodedSince v4.0.0
services
Section titled “services”Config (class)
Section titled “Config (class)”Context service for OpenAI language model configuration.
When to use
Use when you need to provide OpenAI Responses API request defaults through Effect context for language model operations.
Details
Config values are merged with the config object passed to model, make, or
layer, with scoped context values taking precedence.
See
withConfigOverridefor scoping language model request overrides
Signature
declare class ConfigSince v4.0.0