Welcome to Portkey Forum

Updated 3 weeks ago

create virtual key

https://portkey.ai/docs/api-reference/admin-api/control-plane/virtual-keys/create-virtual-key
cannot be triggered on non-enterprise plans ?

Plain Text
import requests

url = "https://api.portkey.ai/v1/virtual-keys"

payload = {
    "provider": "azure-openai",
    "key": "openai-test",
    "name": "Key 1 Azure Open AI",
    "note": "description",
    "apiVersion": "a",
    "deploymentName": "b",
    "resourceName": "c"
}
headers = {
    "x-portkey-api-key": "****",
    "Content-Type": "application/json"
}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)

>>>{
  "success": false,
  "data": {
    "message": "You do not have enough permissions to execute this request",
    "errorCode": "AB03",
    "request_id": "27c675d5-c322-4f7e-89cc-064c26c913f9"
  }
}
W
K
b
18 comments
hey! this should be possible even on non enterprise. Just make sure that the portkey api key you are using has correct scopes.
Attachment
image.png
@Witherwings
I can't see the options for create/update/delete on virtual-keys
FYI, I am an admin type user
Attachments
image.png
image.png
this should be fixed now. can you try again?
Hey @Witherwings It's working now, thank you!
Hey,

Continuing on this thread itself,

I do have access to the proper scopes and permissions now, but still cant create virtual keys programmatically, being hit with 400/500 errors. It works fine so long as I don't use deployments: []

Plain Text
curl --request POST \
  --url https://api.portkey.ai/v1/virtual-keys \
  --header 'Content-Type: application/json' \
  --header 'x-portkey-api-key: iHu65wqZ+H09086' \
  --data '{
  "provider": "azure-openai",
  "key": "1c4bba6669094e2fba84bad323240984",
  "name": "eastus-openai",
  "note": "Account: my-openai, Region: eastus",
  "apiVersion": "2024-10-01-preview",
  "deployments": [
      {
      "apiVersion": "2024-08-01-preview",
      "deploymentName": "gpt-4o",
      "resourceName": "openai-eastus"
      }
    ]
  }'


What am i missing here ?
@Witherwings ^^
Can you help here ?
Hi, @K2. Sorry for the delay.

Please use the following cURL.

Plain Text
  curl --request POST \
  --url https://api.portkey.ai/v1/virtual-keys \
  --header 'content-type: application/json' \
  --header 'x-portkey-api-key: <api_key>' \
  --data '{
  "provider": "azure-openai",
  "key": "key",
  "name": "eastus-openai",
  "note": "Account: my-openai, Region: eastus",
  "resourceName": "resourceName",
  "deploymentConfig": [
    {
      "apiVersion": "2024-08-01-preview",
      "deploymentName": "<deploymentName>",
      "is_default": true
    }
  ]
}'


Our OpenAPI spec is slightly out-of-date with our backend, we will shortly update our OpenAPI spec so the new structure should reflect on our Docs.
Please ping us if you are still having some issue with the above cURL.

Note: deploymentConfig array should contain a config with is_default: true as that will be treated as default config for virtual even multiple deployments are available in single resourcename. if the config is not a default config it should contain a alias key. Please take a look at the following example config for more context.

Plain Text
"deploymentConfig": [
    {
      "apiVersion": "2024-08-01-preview",
      "deploymentName": "<deploymentName>",
      "is_default": true
    },
    {
      "apiVersion": "2024-08-01-preview",
      "deploymentName": "<deploymentName>",
      "is_default": false,
      "alias": "second-modal-optional"
    },
  ]

Make sure there shouldn't be more than 1 default config passed i.e is_default: true should be applied to only 1 deployment config only.
@b4s36t4 Thanks, it's working for me!
Plain Text
curl --request PUT \
  --url https://api.portkey.ai/v1/virtual-keys/dev-eastus-unit-aa74b9 \
  --header 'Content-Type: application/json' \
  --header 'x-portkey-api-key: i2wBueZ+K1FQSf9yCxKuP6J93El1' \
  --data '{ "key": "4531f90749c4d019dc05ebfb1d4v79c"}'

@b4s36t4 @Witherwings
create works fine, but update operations fail, is this not the right schema ?
@K2. Can you share the cURL you're trying to use?!
Plain Text
curl --request PUT \
  --url https://api.portkey.ai/v1/virtual-keys/dev-eastus-unit-aa74b9 \
  --header 'Content-Type: application/json' \
  --header 'x-portkey-api-key: i2wBueZ+K1FQSf9yCxKuP6J93El1' \
  --data '{ "key": "4531f90749c4d019dc05ebfb1d4v79c"}'


{"success":false,"data":{"message":"Invalid request. Please check and try again.","errorCode":"AB01","request_id":"753c0eb8-f44a-4b46-ad09-84a2fca974a6"}}
Yea got it. Give me couple minutes please. Let me take a look.
Plain Text
curl --request PUT \
  --url https://api.portkey.ai/v1/virtual-keys/dev-eastus-unit-aa74b9 \
  --header 'content-type: application/json' \
  --header 'x-portkey-api-key: i2wBueZ+xxyyzzP6J93El1' \
  --data '{
    "name": "eastus-unityopenai",
    "provider": "azure-openai",
    "key": "xxx",
    "note": "Account: unityopenai, Region: eastus",
    "resourceName": "unityopenai",
    "deploymentConfig": [
      {
        "apiVersion": "2024-10-01-preview",
        "deploymentName": "unityprod",
        "is_default": true,
        "alias": "dev-eastus-unityprod"
      },
      {
        "apiVersion": "2024-10-01-preview",
        "deploymentName": "unityprod2",
        "is_default": false,
        "alias": "dev-eastus-unityprod2"
      }
    ]
  }'
>>> {"success":false,"data":{"message":"Something went wrong. Please try again."}}%


Also as a proper PUT it is failing for me.
Hey, there seems to be a BUG from our side for azure specific cases. Please give me some time to push the fix. Will update you within coming 1hr.
Sorry you had to face this issue, but rest assured will update you ASAP.
Hey, @K2 . Can you try now. This cURL should work not.
Few points to note there maybe cases when you'll get 500, this is because either payload is incorrect or one of the keys are incorrect i.e resourceName or deploymentName or apiVersion. This is because we try to fetch the model name from azure before creating, if can't fetch model (can be because above keys might be wrong and azure did throw an error) we throw the error. Anyhow things should be good now, please try it and let us know if still there's an issue.

Thanks for your. patience πŸ™‚
Add a reply
Sign up and join the conversation on Discord