Skip to content

Commit eaed143

Browse files
authored
Merge pull request #110 from Portkey-AI/docs/api-keys-user-type-examples
Add user API key examples and improve API keys documentation
2 parents 3b9ea8e + 8f9dc93 commit eaed143

File tree

1 file changed

+72
-5
lines changed

1 file changed

+72
-5
lines changed

openapi.yaml

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ tags:
9393
- name: Workspaces > Members
9494
description: Create and manage workspace members.
9595
- name: Api-Keys
96-
description: Create, List, Retrieve, Update, and Delete your Portkey Api keys.
96+
description: Create, List, Retrieve, Update, and Delete your Portkey API keys.
9797
- name: Logs Export
9898
description: Exports logs service.
9999
- name: Audit Logs
@@ -16355,7 +16355,9 @@ paths:
1635516355
post:
1635616356
tags:
1635716357
- Api-Keys
16358-
summary: Create Api Keys
16358+
summary: Create API Keys
16359+
description: |
16360+
Creates a new API key.
1635916361
parameters:
1636016362
- name: type
1636116363
in: path
@@ -16588,6 +16590,68 @@ paths:
1658816590
]
1658916591
)
1659016592
print(api_key)
16593+
- lang: python
16594+
label: User API Key
16595+
source: |
16596+
from portkey_ai import Portkey
16597+
16598+
# Initialize the Portkey client
16599+
portkey = Portkey(
16600+
api_key="PORTKEY_API_KEY",
16601+
)
16602+
16603+
# Create a user API key (requires user_id)
16604+
api_key = portkey.api_keys.create(
16605+
name="User API Key",
16606+
type="workspace",
16607+
sub_type="user",
16608+
workspace_id="WORKSPACE_ID",
16609+
user_id="USER_ID", # Required for user API keys
16610+
scopes=[
16611+
"completions.write",
16612+
"logs.view"
16613+
]
16614+
)
16615+
16616+
print(api_key)
16617+
- lang: javascript
16618+
label: User API Key
16619+
source: |
16620+
import { Portkey } from "portkey-ai";
16621+
16622+
const portkey = new Portkey({
16623+
apiKey: "PORTKEY_API_KEY",
16624+
})
16625+
16626+
const apiKey = await portkey.apiKeys.create({
16627+
name: "User API Key",
16628+
type: "workspace",
16629+
"sub-type": "user",
16630+
workspace_id: "WORKSPACE_ID",
16631+
user_id: "USER_ID", // Required for user API keys
16632+
"scopes": [
16633+
"completions.write",
16634+
"logs.view"
16635+
]
16636+
})
16637+
console.log(apiKey);
16638+
- lang: curl
16639+
label: User API Key
16640+
source: |
16641+
curl -X POST https://api.portkey.ai/v1/api-keys/workspace/user
16642+
-H "x-portkey-api-key: PORTKEY_API_KEY" \
16643+
-H "Content-Type: application/json" \
16644+
-d '{
16645+
"name":"User API Key",
16646+
"type":"workspace",
16647+
"sub-type":"user",
16648+
"workspace_id":"WORKSPACE_ID",
16649+
"user_id":"USER_ID",
16650+
"scopes":[
16651+
"completions.write",
16652+
"logs.view"
16653+
]
16654+
}'
1659116655

1659216656
/api-keys:
1659316657
servers:
@@ -16700,7 +16764,9 @@ paths:
1670016764
put:
1670116765
tags:
1670216766
- Api-Keys
16703-
summary: Update Api Keys
16767+
summary: Update API Keys
16768+
description: |
16769+
Updates an existing API key. The API key type (user vs service) and associated user_id cannot be changed after creation.
1670416770
requestBody:
1670516771
content:
1670616772
application/json:
@@ -17083,7 +17149,7 @@ paths:
1708317149
get:
1708417150
tags:
1708517151
- Api-Keys
17086-
summary: Get Api Keys
17152+
summary: Get API Keys
1708717153
parameters:
1708817154
- name: id
1708917155
in: path
@@ -17180,7 +17246,7 @@ paths:
1718017246
delete:
1718117247
tags:
1718217248
- Api-Keys
17183-
summary: Remove a Api Key
17249+
summary: Remove an API Key
1718417250
parameters:
1718517251
- name: id
1718617252
in: path
@@ -31974,6 +32040,7 @@ components:
3197432040
user_id:
3197532041
type: string
3197632042
format: uuid
32043+
description: "**Required** when sub-type path parameter is 'user'. Not required when sub-type is 'service'."
3197732044
example: "c3d4e5f6-a7b8-6c7d-0e1f-2a3b4c5d6e7f"
3197832045
rate_limits:
3197932046
type: array

0 commit comments

Comments
 (0)