Comment on page

Automatic Retries

Automatically reprocess any unsuccessful API requests upto 5 times. We apply an exponential backoff strategy, which spaces out retry attempts to prevent network overload.

How to Use Retries

Portkey Python SDK
Portkey Node SDK
OpenAI SDK (Python)
Add the below header to your API request:
'x-portkey-retry-count': '5'
Your cURL request with retry count set would look like this:
curl -L '' \
-H 'x-portkey-api-key: PORTKEY_API_KEY' \
-H 'x-portkey-retry-count: 5' \
-H 'Content-Type: application/json' \
-d '{
"config": {
"provider": "openai",
"apiKey": "OPENAI_API_KEY"
"params": {
"messages": [{"role": "user","content":"What are the ten tallest buildings in India?"}],
"model": "gpt-4"
Set retry count while constructing the LLM
from portkey import LLMOptions
llm = LLMOptions(
provider="openai", api_key="OPENAI_API_KEY",
Set retry count while constructing the LLM
import { Portkey } from "portkey-ai";
const portkey = new Portkey({
mode: "single",
llms: [{
provider: "openai", virtual_key: "open-ai-xxx",
retry: 5
Add x-portkey-retry-count to OpenAI request header
import openai
openai.api_base = ""
r = openai.Completion.create(
prompt="Once upon a time, Cinderella",
"x-portkey-api-key": "PORTKEY_API_KEY",
"x-portkey-mode": "proxy openai",
"x-portkey-retry-count": "5"