Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual Keys API #126

Merged
merged 17 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export { MainFiles } from "./files";
export { Models } from "./models";
export { Admin } from "./admin";
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 @@ -148,6 +148,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);
beta = {
assistants: new API.Assistants(this),
threads: new API.Threads(this),
Expand Down
5 changes: 3 additions & 2 deletions 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";

type PlatformProperties = {
"x-portkey-runtime"?: string,
Expand Down Expand Up @@ -131,7 +132,7 @@ export function initOpenAIClient(client: Portkey){
maxRetries: 0
})
}
export function toQueryParams(params?: (UsersListParams | UserInviteListParams | WorkspacesListParams | WorkspaceMemberListParams)): string {
export function toQueryParams(params?: (UsersListParams | UserInviteListParams | WorkspacesListParams | WorkspaceMemberListParams |VirtualKeysListParams)): string {
if (!params) {
return '';
}
Expand All @@ -141,4 +142,4 @@ export function toQueryParams(params?: (UsersListParams | UserInviteListParams |
.join('&');

return queryParams ? `?${queryParams}` : '';
}
}
Loading