Skip to main content

Overview

Replicate provides on-demand inference for open-source LLMs including Llama, Mistral, and other models. The provider implements custom prompt formatting for different model families.

Installation

Basic Usage

Constructor Options

keyof typeof ALL_AVAILABLE_REPLICATE_MODELS
default:"llama-3-70b-instruct"
Replicate model name from available models
number
Sampling temperature (minimum 0.01 for Replicate)
number
default:1
Nucleus sampling parameter (Llama 3 defaults to 0.9)
number
Maximum tokens in response (defaults to model’s context window)
ReplicateChatStrategy
Chat prompt formatting strategy (auto-detected from model)
ReplicateSession
Custom Replicate session with API token
boolean
Suppress default model warning

Supported Models

Llama 3

  • llama-3-70b-instruct: 70B parameter, 8K context (default)
  • llama-3-8b-instruct: 8B parameter, 8K context

Llama 2

  • Llama-2-70b-chat-4bit: 70B 4-bit quantized, 4K context
  • Llama-2-70b-chat-old: 70B old version, 4K context
  • Llama-2-13b-chat-4bit: 13B 4-bit quantized, 4K context
  • Llama-2-13b-chat-old: 13B old version, 4K context
  • Llama-2-7b-chat-4bit: 7B 4-bit quantized, 4K context
  • Llama-2-7b-chat-old: 7B old version, 4K context

Chat Strategies

Replicate uses different prompt formats for different model versions:
Available strategies:
  • LLAMA3: Llama 3 format with special tokens
  • META: Standard Llama 2 format
  • METAWBOS: Llama 2 with BOS/EOS tokens
  • A16Z: A16Z-Infra format
  • REPLICATE4BIT: 4-bit model format
  • REPLICATE4BITWNEWLINES: 4-bit format with newlines

Streaming

Custom API Token

With LlamaIndex

Convenience Function

Configuration

Environment Variables

Global Settings

Model Metadata

Access model information:

System Messages

System messages are handled differently based on chat strategy:

Model Selection Guide

Performance Considerations

  1. Cold starts: First request may take longer
  2. Streaming: Better UX for long responses
  3. 4-bit models: Faster but slightly lower quality
  4. Context window: Llama 3 has 8K, Llama 2 has 4K

Error Handling

Legacy Aliases

For backwards compatibility:

Advanced: Custom Prompt Formatting

The provider handles complex prompt formatting automatically:

Best Practices

  1. Use Llama 3 for new projects: Better quality and 8K context
  2. Set appropriate maxTokens: Default can be high, adjust for your use case
  3. Handle cold starts: First request takes longer, consider warming up
  4. Use streaming: Better UX for chat applications
  5. Choose right model size: Balance quality vs. cost and speed
  6. Leverage system messages: Properly format instructions

Pricing

Replicate charges per second of compute time. Check Replicate pricing for current rates.

See Also