Configure authentication
An application needs explicit credential configuration instead of relying on environment lookup.
AI Tools · Function
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.
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.
createReplicate({ baseURL?, apiToken?, headers?, fetch? })| Name | Type | Description |
|---|---|---|
baseURL | string | Optional URL prefix used for API calls; defaults to https://api.replicate.com/v1. |
apiToken | string | Optional API token sent through the Authorization header; defaults to REPLICATE_API_TOKEN. |
headers | Record<string,string> | Optional additional request headers. |
fetch | (input: RequestInfo, init?: RequestInit) => Promise<Response> | Optional custom fetch implementation. |
A customized Replicate provider instance.
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.
An application needs explicit credential configuration instead of relying on environment lookup.
A team routes provider traffic through an internal gateway or proxy.
Tests or infrastructure require controlled request behavior.
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.
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.
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/replicateREPLICATE_API_TOKEN