Effect AI SDK

Typed AI effects with TheRouter.ai model routing

Effect AI SDK pairs well with TheRouter.ai because both prioritize composability and explicit configuration of model/runtime behavior.

Overview

This page mirrors the OpenRouter workflow and adapts it for TheRouter.ai. Use TheRouter.ai as your OpenAI-compatible endpoint and keep model IDs in `provider/model` format.

Installation

Install the required SDKs and keep your TheRouter.ai key in environment variables.

install.sh
npm install effect @effect/ai @effect/ai-openrouter @effect/platform

Configuration

Set TheRouter.ai base URL overrides and pass your API key. Add attribution headers when your app should appear in rankings.

TypeScript
import { OpenRouterClient } from "@effect/ai-openrouter";
const layer = OpenRouterClient.layerConfig({ apiKey: Config.redacted("THEROUTER_API_KEY") });

Caveats

Integration note
Effect programs can fail fast on config issues; make API key presence and model ID validation part of startup checks.

For production rollouts, pin SDK versions and validate model compatibility in staging before broad rollout.