API Reference
Complete reference documentation for all Go-AI SDK APIs, types, and interfaces.
Core AI Functions
High-level functions for working with AI models:
- GenerateText - Generate text completions
- StreamText - Stream text completions in real-time
- GenerateObject - Generate structured data
- StreamObject - Stream structured data
- Embed - Generate embeddings for text
- EmbedMany - Generate embeddings for multiple texts
- Rerank - Rerank documents by relevance
- GenerateImage - Generate images from text
- Transcribe - Transcribe audio to text
- GenerateSpeech - Generate speech from text
- Agent - The
agent.Agentinterface (inpkg/agent) - ToolLoopAgent -
agent.ToolLoopAgent, the SDK's tool-using agent (inpkg/agent)
Tool & Helper APIs
Functions for working with tools and utilities:
- Tool - Define tools for AI models
- Dynamic Tools - Register tools at runtime
- CosineSimilarity - Calculate similarity between vectors
- IsStepCount - Stop condition: stop after n steps
- HasToolCall - Stop condition: stop when a tool is called
- StopCondition - The StopCondition type and StopWhen evaluation
- GenerateID - Generate unique IDs
- Callback Events - Structured lifecycle events for observability
- Stream Transport Helpers - Convert stream results to HTTP-friendly payloads
- Agent UI Stream Helpers - Bridge ToolLoopAgent streams to UI transport
- Middleware Aliases - Middleware APIs re-exported from pkg/ai
Type Definitions
Core types used throughout the SDK:
- Messages - Message types and structures
- Tools - Tool definition types
- Usage - Token usage tracking types
- Errors - Error types and handling
Provider Interfaces
Interfaces for implementing custom providers:
- LanguageModel - Language model interface
- EmbeddingModel - Embedding model interface
- ImageModel - Image generation interface
- SpeechModel - Speech synthesis interface
- TranscriptionModel - Audio transcription interface
- CustomProvider - Create custom providers
Middleware
Middleware system for modifying model behavior:
- WrapLanguageModel - Wrap models with middleware
- MiddlewareInterface - Middleware interface specification
- BuiltInMiddleware - Built-in middleware functions
Schema & Registry
Schema validation and provider registry:
- JSONSchema - JSON schema definitions
- ProviderRegistry - Provider registration system
Error Types
Comprehensive error reference:
- Error Types Overview - All error types and handling
Integrations (experimental)
Adapters and experimental runtimes added in v0.5.0:
- Code Mode - Run model-written JavaScript that calls host tools, in a QuickJS-on-WebAssembly sandbox
- Harness Sandbox: Vercel - Run harness sandboxes on Vercel Sandbox
- LlamaIndex Adapter - Convert a LlamaIndex chat-engine stream to UI message stream chunks