How to beginner · 3 min read

How to get Replicate API token

Quick answer
To get a Replicate API token, sign up or log in at replicate.com, then navigate to your account settings under API Tokens to create and copy your token. Use this token as the REPLICATE_API_TOKEN environment variable for authentication in your Python projects.

PREREQUISITES

  • Python 3.8+
  • Account on replicate.com
  • pip install replicate

Setup

First, create a Replicate account at https://replicate.com. After logging in, go to your user profile and select API Tokens. Generate a new token and copy it securely. Then, set the environment variable REPLICATE_API_TOKEN in your shell or environment to use it in your Python code.

bash
export REPLICATE_API_TOKEN="your_actual_token_here"
output
$ export REPLICATE_API_TOKEN="your_actual_token_here"
$ echo $REPLICATE_API_TOKEN
your_actual_token_here

Step by step

Use the replicate Python package to authenticate with your API token and run a model. Below is a complete example that loads your token from the environment and runs a simple model inference.

python
import os
import replicate

# Ensure your REPLICATE_API_TOKEN is set in environment
client = replicate.Client(api_token=os.environ["REPLICATE_API_TOKEN"])

# Run a model (example: meta-llama-3-8b-instruct)
output = client.run(
    "meta/meta-llama-3-8b-instruct",
    input={"prompt": "Hello, how are you?", "max_tokens": 50}
)

print("Model output:", output)
output
Model output: Hello! I'm doing well, thank you. How can I assist you today?

Common variations

You can also use replicate.run directly without creating a client instance if your environment variable is set. For asynchronous usage, use await replicate.async_run(...) in an async function. Different models can be specified by changing the model string, e.g., "stability-ai/sdxl" for image generation.

python
import replicate

# Simple direct run if REPLICATE_API_TOKEN is set
output = replicate.run(
    "stability-ai/sdxl",
    input={"prompt": "A futuristic cityscape at sunset"}
)
print("Image URL:", output[0])
output
Image URL: https://replicate.delivery/your-generated-image-url.png

Troubleshooting

  • If you get an authentication error, verify your REPLICATE_API_TOKEN is correctly set and has no extra spaces.
  • If the token is missing, ensure you have generated it in your Replicate account settings.
  • For network issues, check your internet connection and firewall settings.

Key Takeaways

  • Get your Replicate API token from your account settings at replicate.com.
  • Set the token as the environment variable REPLICATE_API_TOKEN before running Python code.
  • Use the official replicate Python package for easy API integration.
  • Verify token correctness to avoid authentication errors.
  • You can run different models by changing the model identifier string.
Verified 2026-04 · meta/meta-llama-3-8b-instruct, stability-ai/sdxl
Verify ↗