Skip to main content
Loom provides a unified LlmClient trait with implementations for multiple LLM providers. All providers support streaming, tool calling, and automatic retry with exponential backoff.

Supported Providers

Anthropic (Claude)

Claude 3.5 Sonnet, Opus, and Haiku via Messages API

OpenAI

GPT-4, GPT-4 Turbo, and GPT-3.5 Turbo

Google Vertex AI

Gemini 1.5 Pro and Flash via Vertex AI

ZAI (智谱AI)

Chinese language models from ZhipuAI

Anthropic (Claude)

Loom’s Anthropic integration supports both API key and OAuth authentication, with account pooling for high-volume deployments.

Authentication

Environment variable:

Account Pooling

For high-volume deployments, use AnthropicPool to manage multiple accounts with automatic failover:
Selection strategies:
Distributes requests evenly across all healthy accounts. Best for balanced load distribution.
Routes to the account with the lowest recent usage. Best for quota management.
Uses a primary account until quota exhausted, then fails over to backup accounts.
Automatic failover behavior:
Anthropic enforces a 5-hour rolling window for API usage. The pool automatically detects quota exhaustion errors and fails over to the next healthy account.

Health Monitoring

Monitor pool health via the status API:
Health statuses:
  • Healthy - Account is operational
  • QuotaExceeded - 5-hour quota exhausted, retrying after cooldown
  • Unhealthy - Permanent authentication failure, account disabled

Configuration

Environment variables:

OpenAI

OpenAI integration provides access to GPT models via the Chat Completions API.

Configuration

Environment variables:

Retry Configuration

All LLM clients support configurable retry with exponential backoff:
Implementation:

Rate Limiting

OpenAI returns rate limit information in headers:

Google Vertex AI (Gemini)

Vertex AI provides access to Google’s Gemini models via GCP.

Authentication

Vertex AI uses Application Default Credentials (ADC):
1

Set up credentials

Choose one of the following methods:Service Account (Production):
Default Service Account (GCE/GKE):
User Credentials (Development):
2

Configure client

Token Caching

Vertex AI automatically caches access tokens to reduce auth overhead:

Available Models

gemini-1.5-pro

Best for: Complex reasoning, long context (1M tokens)Flagship model with advanced reasoning capabilities

gemini-1.5-flash

Best for: Fast responses, high throughputOptimized for speed and efficiency

gemini-1.0-pro

Best for: Production workloads, stable APIPrevious generation, highly reliable
Regional endpoints:

ZAI (智谱AI)

ZAI provides Chinese language models from ZhipuAI, compatible with OpenAI’s API format.

Configuration

Environment variables:

Available Models

  • glm-4-plus - Most capable model, best for complex tasks
  • glm-4 - Balanced performance and cost
  • glm-3-turbo - Fast responses, cost-effective
ZAI uses an OpenAI-compatible API, so the client implementation is nearly identical to OpenAIClient with ZAI-specific endpoints.

Unified LlmClient Interface

All providers implement the same LlmClient trait for consistency:

Making Requests

Streaming Responses

Error Handling

Usage Tracking

All providers return token usage information:

Best Practices

Use Streaming

Stream responses for better UX. Users see output immediately instead of waiting for the entire response.

Set Timeouts

Configure appropriate timeouts (default: 5 minutes). Long-running requests should use streaming to avoid timeouts.

Handle Rate Limits

Respect retry-after headers and implement exponential backoff. Use account pooling for high-volume workloads.

Monitor Usage

Track token usage to optimize costs. Consider caching responses for repeated queries.
For implementation details, see the source in crates/loom-server-llm-{anthropic,openai,vertex,zai}/.