Welcome to Portkey Forum

Updated 3 weeks ago

x-portkey-config

In such cases, instead of passing configID, you can pass raw config in the x-portkey-config header. Example curl header:
Plain Text
--header 'x-portkey-config: {"cache": {"mode": "semantic"}}'
S
v
8 comments
So here's what I tried:

Plain Text
curl https://api.portkey.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "x-portkey-api-key: apikeyiek2" \
  -H "x-portkey-virtual-key: open-ai-key-virtual" \
  -H "x-portkey-config: {"cache": {"mode": "semantic"}}" \
  -d '{
    "model": "gpt-3.5-turbo",
    "messages": [
      { "role": "system", "content": "You are a helpful assistant." },
      { "role": "user", "content": "Hello!" }
    ]
  }'

And I got the following response
Plain Text
{"status":"failure","message":"Invalid config passed. You need to pass a valid json"}
If I remove the x-portkey-config, then API call successfully flies. Let me know if you find something wrong with the Curl request.
This is happening because of wrong quotes used. x-portkey-config is surrounded with double quotes and the value of x-portkey-config also has double quotes inside of it. This fixed version should work where all the header quotes have been changes to single quote
Plain Text
curl https://api.portkey.ai/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -H 'x-portkey-api-key: apikeyiek2' \
  -H 'x-portkey-virtual-key: open-ai-key-virtual' \
  -H 'x-portkey-config: {"cache": {"mode": "semantic"}}' \
  -d '{
    "model": "gpt-3.5-turbo",
    "messages": [
      { "role": "system", "content": "You are a helpful assistant." },
      { "role": "user", "content": "Hello!" }
    ]
  }'
Thank you πŸ™‚
You're welcome. Closing this thread as its resolved.
Sorry for re-opening this thread, but I tried similarly with loadbalance

Plain Text
curl --request POST \
  --url https://api.portkey.ai/v1/chat/completions \
  --header 'Content-Type: application/json' \
  --header 'x-portkey-api-key: IxXxxxxxxxxHZxkAxxxxxxxx=' \
  --header 'x-portkey-config: {"strategy":{"mode":"loadbalance"},"targets":[{"virtualKey":"openai-virtual-key","weight":0.7},{"virtualKey":"azure-virtual-key","weight":0.3}]}' \
  --header 'x-portkey-virtual-key: open-ai-key-04ba3e' \
  --data '{
    "model": "gpt-3.5-turbo",
    "messages": [
      { "role": "system", "content": "You are a helpful assistant." },
      { "role": "user", "content": "Hello!" }
    ]
  }'


I have tried removing specific x-portkey-virtual-key too.
I get following response:

Plain Text
{
  "status": "failure",
  "message": "Invalid config passed",
  "errors": [
    "path: targets,0, message: Invalid configuration. It must have either 'provider' and 'api_key', or 'strategy' and 'targets', or 'cache', or 'target'",
    "path: targets,1, message: Invalid configuration. It must have either 'provider' and 'api_key', or 'strategy' and 'targets', or 'cache', or 'target'"
  ]
}


From this I understand this much - I can't use cache and loadbalance in the same config. Is my understanding correct?
I got this working 🟒

Plain Text
curl --request POST \
  --url https://api.portkey.ai/v1/chat/completions \
  --header 'Content-Type: application/json' \
  --header 'x-portkey-api-key: apikey=' \
  --header 'x-portkey-config: {"retry":{"attempts":3},"cache":{"mode":"simple"},"strategy":{"mode":"loadbalance"},"targets":[{"virtual_key":"open-ai-key","weight":0.7},{"virtual_key":"test-virtual-ke","weight":0.3}]}' \
  --header 'x-portkey-virtual-key: open-ai-key' \
  --data '{
    "model": "gpt-3.5-turbo",
    "messages": [
      { "role": "system", "content": "You are a helpful assistant." },
      { "role": "user", "content": "Hello!" }
    ]
  }'
Add a reply
Sign up and join the conversation on Discord