diff --git a/src/apis/apiKeys.ts b/src/apis/apiKeys.ts new file mode 100644 index 0000000..84ba40d --- /dev/null +++ b/src/apis/apiKeys.ts @@ -0,0 +1,138 @@ +import { ApiResource } from "../apiResource"; +import { APIResponseType, ApiClientInterface } from "../_types/generalTypes"; +import { APIPromise, RequestOptions } from "../baseClient"; +import { createHeaders } from "./createHeaders"; +import { toQueryParams } from "../utils"; + +export interface ApiKeysAddParams { + type?: string; + "sub-type"?: string; + name?: string; + description?: string; + workspace_id?:string; + user_id?:string; + rate_limits?: Record[]; + usage_limits?: Record; + scopes: string[]; + defaults?: Record; +} +export interface ApiKeysAddResponse extends APIResponseType { + id?: string; + key?: string; + object?: string; +} +export interface ApiKeysGetParams { + id?: string; +} +export interface ApiKeysGetResponse extends APIResponseType { + id?: string; + key?: string; + name?: string; + description?: string; + type?: string; + organisation_id?: string; + workspace_id?: string; + user_id?: string; + status?: string; + created_at?: Date; + last_updated_at?: Date; + creation_mode?: string; + rate_limits?: Record[]; + usage_limits?: Record; + reset_usage?:number; + scopes?: string[]; + defaults?: Record; + object?: string; +} +export interface ApiKeysUpdateParams { + id?: string; + name?: string; + description?: string; + rate_limits?: Record[]; + usage_limits?: Record; + scopes?: string[]; + defaults?: Record; +} +export interface ApiKeysListParams { + page_size?: number; + current_page?: number; + workspace_id?: string; +} +export interface ApiKeysListResponse extends APIResponseType { + total?: number; + object?: string; + data?: Record[]; +} +export interface ApiKeysDeleteParams { + id?: string; +} +export class ApiKeys extends ApiResource { + create( + _body: ApiKeysAddParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const type = body.type; + const subType = body["sub-type"]; + if (params) { + this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } + } + const response = this.post(`/api-keys/${type}/${subType}`, { body, ...opts }); + return response; + } + + retrieve( + _body: ApiKeysGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const id = body.id; + if (params) { + this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } + } + const response = this.getMethod(`/api-keys/${id}`, { ...opts }); + return response; + } + + update( + _body: ApiKeysUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const id = body.id; + if (params) { + this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } + } + const response = this.put(`/api-keys/${id}`, { body, ...opts }); + return response; + } + list( + _body: ApiKeysListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ):APIPromise{ + const body = _body; + if (params) { + this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } + } + const query = toQueryParams(body); + const response = this.getMethod(`/api-keys${query}`, {...opts }); + return response; + } + delete( + _body: ApiKeysDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ):APIPromise{ + const body = _body; + const id=body.id; + if (params) { + this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } + } + const response = this.deleteMethod(`/api-keys/${id}`, { body, ...opts }); + return response; + } +} diff --git a/src/apis/index.ts b/src/apis/index.ts index 251be74..82eee35 100644 --- a/src/apis/index.ts +++ b/src/apis/index.ts @@ -19,3 +19,4 @@ export { Audio } from "./audio" export { VectorStores } from "./vectorStores" export { BetaChat } from "./betaChat" export { Uploads } from "./uploads" +export { ApiKeys } from "./apiKeys" diff --git a/src/client.ts b/src/client.ts index 4c1db23..dcf1861 100644 --- a/src/client.ts +++ b/src/client.ts @@ -30,15 +30,15 @@ export class Portkey extends ApiClient { azureResourceName?: string | null | undefined; azureDeploymentId?: string | null | undefined; azureApiVersion?: string | null | undefined; - azureEndpointName?: string | null | undefined; + azureEndpointName?: string | null | undefined; huggingfaceBaseUrl?: string | null | undefined; forwardHeaders?: Array | null | undefined; requestTimeout?: number | null | undefined; cacheNamespace?: string | null | undefined; strictOpenAiCompliance?: boolean | null | undefined; anthropicBeta?: string | null | undefined; - anthropicVersion?: string | null | undefined; - mistralFimCompletion?: string | null | undefined; + anthropicVersion?: string | null | undefined; + mistralFimCompletion?: string | null | undefined; constructor({ apiKey = readEnv("PORTKEY_API_KEY") ?? null, baseURL = readEnv("PORTKEY_BASE_URL") ?? null, @@ -63,15 +63,15 @@ export class Portkey extends ApiClient { azureResourceName, azureDeploymentId, azureApiVersion, - azureEndpointName, + azureEndpointName, huggingfaceBaseUrl, forwardHeaders, cacheNamespace, requestTimeout, strictOpenAiCompliance, anthropicBeta, - anthropicVersion, - mistralFimCompletion + anthropicVersion, + mistralFimCompletion }: ApiClientInterface) { super({ @@ -99,14 +99,14 @@ export class Portkey extends ApiClient { azureResourceName, azureDeploymentId, azureApiVersion, - azureEndpointName, + azureEndpointName, huggingfaceBaseUrl, forwardHeaders, requestTimeout, strictOpenAiCompliance, anthropicBeta, - anthropicVersion, - mistralFimCompletion + anthropicVersion, + mistralFimCompletion }); this.apiKey = apiKey; @@ -135,14 +135,14 @@ export class Portkey extends ApiClient { this.azureResourceName = azureResourceName; this.azureDeploymentId = azureDeploymentId; this.azureApiVersion = azureApiVersion; - this.azureEndpointName = azureEndpointName; + this.azureEndpointName = azureEndpointName; this.huggingfaceBaseUrl = huggingfaceBaseUrl; this.forwardHeaders = forwardHeaders; this.requestTimeout = requestTimeout; this.strictOpenAiCompliance = strictOpenAiCompliance; this.anthropicBeta = anthropicBeta; - this.anthropicVersion = anthropicVersion; - this.mistralFimCompletion = mistralFimCompletion; + this.anthropicVersion = anthropicVersion; + this.mistralFimCompletion = mistralFimCompletion; } completions: API.Completions = new API.Completions(this); @@ -160,6 +160,7 @@ export class Portkey extends ApiClient { audio = new API.Audio(this); uploads = new API.Uploads(this); admin = new API.Admin(this); + apiKeys = new API.ApiKeys(this); configs = new API.Configs(this); beta = { assistants: new API.Assistants(this), @@ -168,7 +169,6 @@ export class Portkey extends ApiClient { chat: new API.BetaChat(this), }; - post = ( url: string, _body: PostBodyParams, diff --git a/src/utils.ts b/src/utils.ts index 9c91253..6e52bdc 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -3,6 +3,7 @@ import { createResponseHeaders } from "./streaming"; import OpenAI from "openai"; import type { Portkey } from "./index"; import { UserInviteListParams, UsersListParams, WorkspaceMemberListParams, WorkspacesListParams } from "./apis/admin"; +import { ApiKeysListParams } from "./apis/apiKeys"; import { CongfigsListParams } from "./apis/configs"; type PlatformProperties = { @@ -132,7 +133,7 @@ export function initOpenAIClient(client: Portkey){ maxRetries: 0 }) } -export function toQueryParams(params?: (UsersListParams | UserInviteListParams | WorkspacesListParams | WorkspaceMemberListParams | CongfigsListParams)): string { +export function toQueryParams(params?: (UsersListParams | UserInviteListParams | WorkspacesListParams | WorkspaceMemberListParams | ApiKeysListParams | CongfigsListParams)): string { if (!params) { return ''; } @@ -142,4 +143,4 @@ export function toQueryParams(params?: (UsersListParams | UserInviteListParams | .join('&'); return queryParams ? `?${queryParams}` : ''; -} \ No newline at end of file +}