effect-ai-provider

Configure and compose AI provider layers using @effect/ai packages for language model integration.

3|Updated Apr 1, 2026
One-click install
npx skills add https://github.com/mpsuesser/opencode-effect-enforcer --skill effect-ai-provider-mpsuesser
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: effect-ai-provider
Source: https://github.com/mpsuesser/opencode-effect-enforcer/tree/main/skills/effect-ai-provider
Command: npx skills add https://github.com/mpsuesser/opencode-effect-enforcer --skill effect-ai-provider-mpsuesser

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @effect/ai-anthropic, @effect/ai-openai, @effect/ai-openrouter, effect.

What problem does it solve? Setting up AI language model providers in Effect applications involves juggling API keys, HTTP clients, model configuration, and fallback logic. This Skill provides the correct patterns for wiring Anthropic, OpenAI, OpenAI-compatible, and OpenRouter providers into Effect layers without common mistakes like hardcoded keys or missing HTTP client layers. ## Core Features & Use Cases - Provider Layer Setup: Build client and model layers for Anthropic, OpenAI, OpenAI-compatible endpoints, and OpenRouter using Config.Redacted for secrets and FetchHttpClient for transport. - Multi-Provider Fallback: Use ExecutionPlan to retry cheaper models first and fall back to more capable ones, with observable attempt lifecycle events. - Stateful Chat & Streaming: Maintain conversation history with Chat.fromPrompt, export and restore sessions as JSON, and stream text deltas through Effect Streams. - Use Case: Build an AiWriter service that drafts announcements with GPT-5.2, falls back to Claude Opus on failure, keeps a chat session with history, and wraps all AiError values into a domain-specific tagged error. ## Quick Start Ask the agent to set up an Anthropic language model layer with an API key from Config and use it to generate text in an Effect program.

Frequently Asked Questions about effect-ai-provider

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up an Anthropic language model layer in Effect?

Create a client layer with AnthropicClient.layerConfig using Config.Redacted for the API key, provide FetchHttpClient.layer, then call AnthropicLanguageModel.model with a model ID like claude-opus-4-6. The model constructor returns a Model.Model usable with Effect.provide or ExecutionPlan.

How do I implement multi-provider fallback with Effect AI?

Use ExecutionPlan.make with ordered steps, each specifying a provider model and attempt count. Call captureRequirements inside a Layer.effect to satisfy client requirements, then apply the plan with Effect.withExecutionPlan, optionally observing AttemptStart, AttemptSuccess, and AttemptFailure events.

Does @effect/ai support Google or Amazon Bedrock providers?

No @effect/ai-google or @effect/ai-amazon-bedrock packages exist. Use @effect/ai-openrouter to access Google or Bedrock models through OpenRouter's unified API with provider-prefixed model IDs like anthropic/claude-sonnet-4.

Can I use OpenAI-compatible APIs with @effect/ai-openai?

Yes, pass apiUrl in OpenAiClient.layerConfig to point at any OpenAI-compatible endpoint such as Azure OpenAI or local models. Use OpenAiConfig.withClientTransform for middleware, proxy, tracing, or header transforms on requests.

Why does my Effect AI provider layer fail at runtime?

The most common cause is a missing HTTP client: every provider client layer requires an HttpClient, so pipe Layer.provide(FetchHttpClient.layer) into the client layer. Also verify API keys come from Config.Redacted rather than hardcoded strings.

How do I maintain chat conversation history with Effect AI?

Create a session with Chat.fromPrompt using a system prompt, or Chat.empty for a blank session. Each generateText call updates history automatically; access it via Ref.get on session.history, persist with session.exportJson, and restore with Chat.fromJson.