Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Function

createReplicate

createReplicate creates a customized Replicate provider instance from @ai-sdk/replicate. Configure its API token, request URL, headers, or fetch implementation before selecting Replicate models.

How it works

createReplicate builds a customized Replicate provider instance from optional settings. The returned provider can be used to select Replicate models, while authentication defaults to the REPLICATE_API_TOKEN environment variable when apiToken is not supplied.

Syntax

createReplicate({ baseURL?, apiToken?, headers?, fetch? })

Parameters

NameTypeDescription
baseURLstringOptional URL prefix used for API calls; defaults to https://api.replicate.com/v1.
apiTokenstringOptional API token sent through the Authorization header; defaults to REPLICATE_API_TOKEN.
headersRecord<string,string>Optional additional request headers.
fetch(input: RequestInfo, init?: RequestInit) => Promise<Response>Optional custom fetch implementation.

Returns

A customized Replicate provider instance.

Key points

  • Import createReplicate when the provider needs custom configuration rather than using the package's default provider instance.
  • Call the factory with a settings object to obtain a configured Replicate provider.
  • baseURL lets applications direct API requests through a different URL prefix, including a proxy.
  • apiToken supplies the credential used in the request Authorization header.
  • Without a custom baseURL, requests use Replicate's v1 API prefix.
  • Custom request headers can be supplied through the headers setting.

Common mistakes

  • If apiToken is omitted, authentication depends on the REPLICATE_API_TOKEN environment variable being available.

Example: Create a configured Replicate provider

import { createReplicate } from '@ai-sdk/replicate';

const replicate = createReplicate({
  apiToken: process.env.REPLICATE_API_TOKEN ?? '',
});

export const model = replicate('meta/meta-llama-3-8b-instruct');

Creates a Replicate provider configured with an API token, then uses it to select a model.

When to use it

Configure authentication

An application needs explicit credential configuration instead of relying on environment lookup.

Customize the API endpoint

A team routes provider traffic through an internal gateway or proxy.

Inject headers or fetch

Tests or infrastructure require controlled request behavior.

Interview questions

QWhat is createReplicate used for?

createReplicate is the factory for a customized Replicate provider instance from @ai-sdk/replicate. It accepts provider settings such as apiToken, baseURL, headers, and fetch.

Follow-up: How would you route requests through a proxy? Set baseURL to the proxy's URL prefix when creating the provider.

QHow does authentication work?

apiToken is sent in the Authorization header. When it is not explicitly provided, the provider reads REPLICATE_API_TOKEN from the environment.

Follow-up: What should a deployment configure if it does not pass apiToken programmatically? It should provide REPLICATE_API_TOKEN in the runtime environment.

QWhat does the returned provider enable?

The factory returns a provider instance that can be used to select Replicate models. The provider package is @ai-sdk/replicate, and the default API prefix is https://api.replicate.com/v1.

Follow-up: When would the default provider be preferable? Use the exported replicate instance when no custom settings are needed.

  • replicate
  • @ai-sdk/replicate
  • REPLICATE_API_TOKEN

Source: Replicate - AI SDK. Checked 2026-10-15.