Links
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

cURL
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 'https://api.portkey.ai/v1/chatComplete' \
-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",
retry=5
)
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 = "https://api.portkey.ai/v1/proxy"
r = openai.Completion.create(
model="gpt-3.5-turbo-instruct",
prompt="Once upon a time, Cinderella",
headers={
"x-portkey-api-key": "PORTKEY_API_KEY",
"x-portkey-mode": "proxy openai",
"x-portkey-retry-count": "5"
}
)
print(r.choices[0].text)