Replicate is a platform for building and running machine learning models.
Replicate does not have a standarized JSON body format for their inference API, hence it is not possible to use unified API to interact with Replicate.
Portkey instead provides a proxy to Replicate, allowing you to use virtual keys and observability features.
To use Replicate with Portkey, get your Replicate API key from here, then add it to Portkey to create your Replicate virtual key.
import Portkey from 'portkey-ai'const portkey = new Portkey({ apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"] virtualKey: "VIRTUAL_KEY" // Your Replicate Virtual Key})
import Portkey from 'portkey-ai'const portkey = new Portkey({ apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"] virtualKey: "VIRTUAL_KEY" // Your Replicate Virtual Key})
from portkey_ai import Portkeyportkey = Portkey( api_key="PORTKEY_API_KEY", # Replace with your Portkey API key virtual_key="VIRTUAL_KEY" # Replace with your virtual key for Replicate)
from portkey_ai import Portkeyportkey = Portkey( api_key="PORTKEY_API_KEY", # Replace with your Portkey API key virtual_key="REPLICATE_VIRTUAL_KEY",)response = portkey.post( url="predictions", # Replace with the endpoint you want to call)print(response)
from portkey_ai import Portkeyportkey = Portkey( api_key="PORTKEY_API_KEY", # Replace with your Portkey API key virtual_key="REPLICATE_VIRTUAL_KEY",)response = portkey.post( url="predictions", # Replace with the endpoint you want to call)print(response)
import Portkey from 'portkey-ai';// Initialize the Portkey clientconst portkey = new Portkey({ apiKey: "PORTKEY_API_KEY", // Replace with your Portkey API key virtualKey: "REPLICATE_VIRTUAL_KEY", // Add your Replicate's virtual key});response = portkey.post( url="predictions", # Replace with the endpoint you want to call)print(response)
import OpenAI from 'openai'; // We're using the v4 SDKimport { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai'const openai = new OpenAI({ apiKey: 'REPLICATE_API_KEY', // defaults to process.env["OPENAI_API_KEY"], baseURL: PORTKEY_GATEWAY_URL, defaultHeaders: createHeaders({ virtualKey: "REPLICATE_VIRTUAL_KEY", apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"] })});response = openai.post( url="predictions", # Replace with the endpoint you want to call)print(response)
from openai import OpenAIfrom portkey_ai import PORTKEY_GATEWAY_URL, createHeadersopenai = OpenAI( api_key='REPLICATE_API_KEY', base_url=PORTKEY_GATEWAY_URL, default_headers=createHeaders( provider="replicate", api_key="PORTKEY_API_KEY" ))response = openai.post( url="predictions", # Replace with the endpoint you want to call)print(response)