@effect/ai provides Effect-native integrations for popular AI services, enabling type-safe interactions with language models, embeddings, and other AI capabilities.
Installation
Supported Providers
Install provider-specific packages:OpenAI
Anthropic
Google AI
Amazon Bedrock
OpenRouter
OpenAI Quick Start
Streaming Responses
Stream completions for real-time output:Embeddings
Generate vector embeddings:Anthropic Claude
Function Calling
Use structured outputs and function calling:Schema Validation
Combine with Effect schemas for type safety:Token Management
Track and manage token usage:Error Handling
Handle AI API errors gracefully:Best Practices
- Rate Limiting: Implement backoff strategies for API limits
- Caching: Cache responses for repeated queries
- Cost Control: Monitor token usage and set limits
- Error Recovery: Handle transient failures with retries
- Type Safety: Use schemas for structured outputs
- Streaming: Use streaming for better UX on long responses
Example: RAG System
Build a Retrieval-Augmented Generation system:Related Resources
Introduction
Getting started guide
API Reference
Complete API documentation
@effect/platform
HTTP client for API requests
Effect Schema
Schema validation and parsing