diff --git a/src/apis/index.ts b/src/apis/index.ts index 82eee35..6deac4b 100644 --- a/src/apis/index.ts +++ b/src/apis/index.ts @@ -13,6 +13,7 @@ export { Models } from "./models"; export { Admin } from "./admin"; export { Configs } from "./configs"; export { Batches } from "./batches"; +export { VirtualKeys } from "./virtualKeys"; export { FineTuning } from "./fineTuning" export { Moderations } from "./moderations" export { Audio } from "./audio" diff --git a/src/apis/virtualKeys.ts b/src/apis/virtualKeys.ts new file mode 100644 index 0000000..9af0437 --- /dev/null +++ b/src/apis/virtualKeys.ts @@ -0,0 +1,135 @@ +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 VirtualKeysAddParams { + name?: string; + provider?: string; + key?: string; + note?: string | null; + apiVersion?: string | null; + resourceName?: string | null; + deploymentName?: string | null; + workspace_id?: string; + usage_limits?: Record; + [key: string]: any; +} +export interface VirtualKeysAddResponse extends APIResponseType { + id?: string; + slug?:string; + object?: string; +} +export interface VirtualKeysGetParams { + slug?: string; +} + +export interface VirtualKeysGetResponse extends APIResponseType { + id?: string, + ai_provider_name?: string, + model_config?: Record, + masked_api_key?: string, + slug?: string, + name?: string, + usage_limits?: Record, + status?: string, + note?: null|string, + created_at?: Date, + rate_limits?: Record[], + object?: string, +} +export interface VirtualKeysListParams { + workspace_id?: string; +} +export interface VirtualKeysListResponse extends APIResponseType { + object?:string, + total?:number, + data?: VirtualKeysGetResponse[]; +} + +export interface VirtualKeysUpdateParams { + slug?: string; + name?: string; + key?: string; + note?: string | null; + usage_limits?: Record; + rate_limits?: Record[]; + [key: string]: any; +} +export interface VirtualKeysUpdateResponse extends APIResponseType { + id?:string; + slug?:string; + object?: string; +} +export interface VirtualKeysDeleteParams { + slug?: string; +} + + +export class VirtualKeys extends ApiResource { + create( + body: VirtualKeysAddParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + if (params) { + this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } + } + const response = this.post('/virtual-keys', { body, ...opts }); + return response; + } + + list( + _body?: VirtualKeysListParams, + 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(`/virtual-keys${query}`, { ...opts }); + return response; + } + + retrieve( + body: VirtualKeysGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { slug } = body; + if (params) { + this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } + } + const response = this.getMethod(`/virtual-keys/${slug}`, { ...opts }); + return response; + } + + update( + body: VirtualKeysUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { slug, ...restBody } = body; + if (params) { + this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } + } + const response = this.put(`/virtual-keys/${slug}`, { body: restBody, ...opts }); + return response; + } + + delete( + body: VirtualKeysDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { slug } = body; + if (params) { + this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } + } + const response = this.deleteMethod(`/virtual-keys/${slug}`, { ...opts }); + return response; + } +} \ No newline at end of file diff --git a/src/client.ts b/src/client.ts index dcf1861..bab8c7f 100644 --- a/src/client.ts +++ b/src/client.ts @@ -160,6 +160,7 @@ export class Portkey extends ApiClient { audio = new API.Audio(this); uploads = new API.Uploads(this); admin = new API.Admin(this); + virtualKeys = new API.VirtualKeys(this); apiKeys = new API.ApiKeys(this); configs = new API.Configs(this); beta = { diff --git a/src/utils.ts b/src/utils.ts index 6e52bdc..4fd8bff 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 { VirtualKeysListParams } from "./apis/virtualKeys"; import { ApiKeysListParams } from "./apis/apiKeys"; import { CongfigsListParams } from "./apis/configs"; @@ -133,7 +134,7 @@ export function initOpenAIClient(client: Portkey){ maxRetries: 0 }) } -export function toQueryParams(params?: (UsersListParams | UserInviteListParams | WorkspacesListParams | WorkspaceMemberListParams | ApiKeysListParams | CongfigsListParams)): string { +export function toQueryParams(params?: (UsersListParams | UserInviteListParams | WorkspacesListParams | WorkspaceMemberListParams |VirtualKeysListParams | ApiKeysListParams | CongfigsListParams)): string { if (!params) { return ''; }