Skip to content
Effect Days 2026 Get your ticket

Model

The Model module provides a unified interface for AI service providers.

This module enables creation of provider-specific AI models that can be used interchangeably within the Effect AI ecosystem. It combines Layer functionality with provider identification, allowing for seamless switching between different AI service providers while maintaining type safety.

Example

import { Model, LanguageModel } from "@effect/ai"
import { Effect, Layer } from "effect"
declare const myAnthropicLayer: Layer.Layer<LanguageModel.LanguageModel>
const anthropicModel = Model.make("anthropic", myAnthropicLayer)
const program = Effect.gen(function* () {
const response = yield* LanguageModel.generateText({
prompt: "Hello, world!"
})
return response.text
}).pipe(
Effect.provide(anthropicModel)
)
5 exports Added in v1.0.0 Source

Constructors

make

Added in v1.0.0 Source

Creates a Model from a provider name and a Layer that constructs AI services.

Signature

declare function make<Provider extends string, Provides, Requires>(provider: Provider, layer: Layer<Provides, never, Requires>): Model<Provider, Provides, Requires>

Example

import { Model, LanguageModel } from "@effect/ai"
import { Effect, Layer } from "effect"
declare const bedrockLayer: Layer.Layer<LanguageModel.LanguageModel>
// Model automatically provides ProviderName service
const checkProviderAndGenerate = Effect.gen(function* () {
const provider = yield* Model.ProviderName
console.log(`Generating with: ${provider}`)
return yield* LanguageModel.generateText({
prompt: `Hello from ${provider}!`
})
})
const program = checkProviderAndGenerate.pipe(
Effect.provide(Model.make("amazon-bedrock", bedrockLayer))
)
// Will log: "Generating with: amazon-bedrock"

Context

ProviderName

Added in v1.0.0 Source

Service tag that provides the current large language model provider name.

This tag is automatically provided by Model instances and can be used to access the name of the provider that is currently in use within a given Effect program.

Signature

declare class ProviderName extends any {
constructor();
}

Models

Model interface

Added in v1.0.0 Source

A Model represents a provider-specific AI service.

A Model can be used directly as a Layer to provide a particular model implementation to an Effect program.

A Model can also be used as an Effect to "lift" dependencies of the Model constructor into the parent Effect. This is particularly useful when you want to use a Model from within an Effect service.

Signature

interface Model<in out Provider, in out Provides, in out Requires> extends Layer<Provides | ProviderName, never, Requires>, Effect<Layer.Layer<Provides | ProviderName>, never, Requires> {
readonly "~@effect/ai/Model": "~@effect/ai/Model";
readonly provider: Provider;
}

Type Ids

TypeId

Added in v1.0.0 Source

Unique identifier for Model instances.

Signature

declare const TypeId: "~@effect/ai/Model"

TypeId type

Added in v1.0.0 Source

Type-level representation of the Model identifier.

Signature

type TypeId = typeof TypeId