Replicate is a platform for running machine learning models in the cloud.
Replicate doesn’t use a standardized JSON format for their API, so Portkey acts as a proxy, managing authentication and logging all requests.
Quick Start
from portkey_ai import Portkey
# 1. Install: pip install portkey-ai
# 2. Add @replicate provider in model catalog
# 3. Use it:
portkey = Portkey(
api_key="PORTKEY_API_KEY",
provider="@replicate"
)
response = portkey.post(
url="predictions",
data={
"version": "MODEL_VERSION_ID",
"input": {"prompt": "Hello, world!"}
}
)
print(response)
import Portkey from 'portkey-ai'
// 1. Install: npm install portkey-ai
// 2. Add @replicate provider in model catalog
// 3. Use it:
const portkey = new Portkey({
apiKey: "PORTKEY_API_KEY",
provider: "@replicate"
})
const response = await portkey.post({
url: "predictions",
data: {
version: "MODEL_VERSION_ID",
input: { prompt: "Hello, world!" }
}
})
console.log(response)
# 1. Add @replicate provider in model catalog
# 2. Use it:
curl https://api.portkey.ai/v1/predictions \
-H "Content-Type: application/json" \
-H "x-portkey-api-key: $PORTKEY_API_KEY" \
-d '{
"version": "MODEL_VERSION_ID",
"input": {"prompt": "Hello, world!"}
}'
Add Provider in Model Catalog
Before making requests, add Replicate to your Model Catalog:
- Go to Model Catalog → Add Provider
- Select Replicate
- Enter your Replicate API token
- Name your provider (e.g.,
replicate)
Complete Setup Guide
See all setup options and detailed configuration instructions
Using Replicate with Portkey
Since Replicate doesn’t follow the OpenAI format, use Portkey’s post() method to interact with any Replicate endpoint:
from portkey_ai import Portkey
portkey = Portkey(
api_key="PORTKEY_API_KEY",
provider="@replicate"
)
# Run a prediction
response = portkey.post(
url="predictions",
data={
"version": "stability-ai/sdxl:...",
"input": {
"prompt": "A serene landscape"
}
}
)
print(response)
import Portkey from 'portkey-ai';
const portkey = new Portkey({
apiKey: 'PORTKEY_API_KEY',
provider: '@replicate'
});
// Run a prediction
const response = await portkey.post({
url: "predictions",
data: {
version: "stability-ai/sdxl:...",
input: {
prompt: "A serene landscape"
}
}
});
console.log(response);
Supported Endpoints
Portkey proxies all Replicate API endpoints:
/predictions - Create predictions
/predictions/{prediction_id} - Get prediction status
/predictions/{prediction_id}/cancel - Cancel predictions
/models - List models
/collections - List collections
See Replicate’s API documentation for complete endpoint details.
Next Steps
Observability
Monitor and trace your Replicate requests
Metadata
Add custom metadata to requests
Caching
Cache Replicate responses
Guardrails
Add input/output checks
For complete SDK documentation:
SDK Reference
Complete Portkey SDK documentation