Skip to content

Commit

Permalink
Merge pull request #126 from Portkey-AI/feat/virtualKeys
Browse files Browse the repository at this point in the history
Virtual Keys API
  • Loading branch information
VisargD authored Oct 9, 2024
2 parents 2b73395 + 0e3265e commit db71a0f
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
135 changes: 135 additions & 0 deletions src/apis/virtualKeys.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>;
[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<string, any>,
masked_api_key?: string,
slug?: string,
name?: string,
usage_limits?: Record<string, any>,
status?: string,
note?: null|string,
created_at?: Date,
rate_limits?: Record<string, any>[],
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<string, any>;
rate_limits?: Record<string, any>[];
[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<VirtualKeysAddResponse> {
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const response = this.post<VirtualKeysAddResponse>('/virtual-keys', { body, ...opts });
return response;
}

list(
_body?: VirtualKeysListParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<VirtualKeysListResponse> {
const body=_body;
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const query = toQueryParams(body);
const response = this.getMethod<VirtualKeysListResponse>(`/virtual-keys${query}`, { ...opts });
return response;
}

retrieve(
body: VirtualKeysGetParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<VirtualKeysGetResponse> {
const { slug } = body;
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const response = this.getMethod<VirtualKeysGetResponse>(`/virtual-keys/${slug}`, { ...opts });
return response;
}

update(
body: VirtualKeysUpdateParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<VirtualKeysUpdateResponse> {
const { slug, ...restBody } = body;
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const response = this.put<VirtualKeysUpdateResponse>(`/virtual-keys/${slug}`, { body: restBody, ...opts });
return response;
}

delete(
body: VirtualKeysDeleteParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<any> {
const { slug } = body;
if (params) {
this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) }
}
const response = this.deleteMethod<any>(`/virtual-keys/${slug}`, { ...opts });
return response;
}
}
1 change: 1 addition & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
3 changes: 2 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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 '';
}
Expand Down

0 comments on commit db71a0f

Please sign in to comment.