From b65a216fb63f95a4f38b9d3d8af09094589832fa Mon Sep 17 00:00:00 2001 From: Chandra Kiran G Date: Tue, 14 Apr 2026 16:00:10 +0530 Subject: [PATCH 1/4] feat: Add analytics APIs --- src/apis/analytics.ts | 559 ++++++++++++++++++++++++++++++++++++++++++ src/apis/index.ts | 1 + src/client.ts | 1 + src/utils.ts | 14 +- src/version.ts | 2 +- 5 files changed, 570 insertions(+), 7 deletions(-) create mode 100644 src/apis/analytics.ts diff --git a/src/apis/analytics.ts b/src/apis/analytics.ts new file mode 100644 index 0000000..b4b738a --- /dev/null +++ b/src/apis/analytics.ts @@ -0,0 +1,559 @@ +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 AnalyticsBaseParams { + time_of_generation_min: string; + time_of_generation_max: string; + total_units_min?: number; + total_units_max?: number; + cost_min?: number; + cost_max?: number; + prompt_token_min?: number; + prompt_token_max?: number; + completion_token_min?: number; + completion_token_max?: number; + status_code?: string; + page_size?: number; + weighted_feedback_min?: number; + weighted_feedback_max?: number; + order_by?: string; + order_by_type?: string; + virtual_keys?: string; + configs?: string; + workspace_slug?: string; + api_key_ids?: string; + ai_org_model?: string; + metadata?: string; + cache_status?: string; +} + +export type AnalyticsGraphsGetParams = AnalyticsBaseParams; + +export interface AnalyticsGroupsGetParams extends AnalyticsBaseParams { + page_size?: number; + current_page?: number; +} + +export type AnalyticsGroupByValue = + | 'ai_service' + | 'model' + | 'status_code' + | 'api_key' + | 'config' + | 'workspace' + | 'provider' + | 'prompt'; + +export type AnalyticsColumnValue = + | 'requests' + | 'cost' + | 'total_tokens' + | 'avg_tokens' + | 'avg_input_tokens' + | 'avg_output_tokens' + | 'avg_latency' + | 'p95_latency' + | 'p99_latency' + | 'success_rate' + | 'error_count' + | 'cache_hit_rate' + | 'last_seen' + | 'first_seen'; + +export interface AnalyticsGroupedDataParams extends AnalyticsGroupsGetParams { + columns?: string; + include_total?: boolean; +} + +export type AnalyticsSummaryGetParams = AnalyticsBaseParams; + +export class Analytics extends ApiResource { + graphs: AnalyticsGraphs; + groups: AnalyticsGroups; + summary: AnalyticsSummary; + + constructor(client: any) { + super(client); + this.graphs = new AnalyticsGraphs(client); + this.groups = new AnalyticsGroups(client); + this.summary = new AnalyticsSummary(client); + } +} + +export class AnalyticsGraphs extends ApiResource { + requests( + body: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/requests${queryParams}`, + { ...opts } + ); + return response; + } + + cost( + body: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`/analytics/graphs/cost${queryParams}`, { + ...opts, + }); + return response; + } + + latency( + body: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`/analytics/graphs/latency${queryParams}`, { + ...opts, + }); + return response; + } + + tokens( + body: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`/analytics/graphs/tokens${queryParams}`, { + ...opts, + }); + return response; + } + + users( + body: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`/analytics/graphs/users${queryParams}`, { + ...opts, + }); + return response; + } + + usersRequests( + body: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/users-requests${queryParams}`, + { + ...opts, + } + ); + return response; + } + + errors( + body: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`/analytics/graphs/errors${queryParams}`, { + ...opts, + }); + return response; + } + + errors_rate( + body: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/errors-rate${queryParams}`, + { + ...opts, + } + ); + return response; + } + + errors_stack( + body: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/errors-stack${queryParams}`, + { + ...opts, + } + ); + return response; + } + + errors_status_code( + body: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/errors-status-code${queryParams}`, + { + ...opts, + } + ); + return response; + } + + requests_rescued( + body: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/requests-rescued${queryParams}`, + { + ...opts, + } + ); + return response; + } + + cache_hit_rate( + body: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/cache-hit-rate${queryParams}`, + { + ...opts, + } + ); + return response; + } + + cache_latency( + body: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/cache-latency${queryParams}`, + { + ...opts, + } + ); + return response; + } + + feedbacks( + body: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/feedbacks${queryParams}`, + { + ...opts, + } + ); + return response; + } + + feedbacks_score( + body: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + + const response = this.getMethod( + `/analytics/graphs/feedbacks/score${queryParams}`, + { + ...opts, + } + ); + + return response; + } + + feedbacks_weighted( + body: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + + const response = this.getMethod( + `/analytics/graphs/feedbacks/weighted${queryParams}`, + { + ...opts, + } + ); + return response; + } + + feedback_ai_models( + body: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + + const response = this.getMethod( + `/analytics/graphs/feedbacks/ai-models${queryParams}`, + { + ...opts, + } + ); + return response; + } +} + +export class AnalyticsGroups extends ApiResource { + users( + body: AnalyticsGroupsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`/analytics/groups/users${queryParams}`, { + ...opts, + }); + return response; + } + + aiModels( + body: AnalyticsGroupsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/groups/ai-models${queryParams}`, + { + ...opts, + } + ); + return response; + } + + workspaces( + body: AnalyticsGroupsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/groups/workspaces${queryParams}`, + { + ...opts, + } + ); + return response; + } + + metadata( + metadataKey: string, + body: AnalyticsGroupsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/groups/metadata/${metadataKey}${queryParams}`, + { + ...opts, + } + ); + return response; + } + + groupedData( + groupBy: AnalyticsGroupByValue, + body: AnalyticsGroupedDataParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/groups/${groupBy}${queryParams}`, + { + ...opts, + } + ); + return response; + } +} + +export class AnalyticsSummary extends ApiResource { + cache( + body: AnalyticsSummaryGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`/analytics/summary/cache${queryParams}`, { + ...opts, + }); + return response; + } +} diff --git a/src/apis/index.ts b/src/apis/index.ts index 3bbb992..f8eabf2 100644 --- a/src/apis/index.ts +++ b/src/apis/index.ts @@ -38,3 +38,4 @@ export { Conversations } from './conversations'; export { Videos } from './videos'; export { ChatKit } from './chatkit'; export { Guardrails } from './guardrails'; +export { Analytics } from './analytics'; diff --git a/src/client.ts b/src/client.ts index 1566c3e..f2fefa9 100644 --- a/src/client.ts +++ b/src/client.ts @@ -223,6 +223,7 @@ export class Portkey extends ApiClient { realtime: new API.Realtime(this), chatkit: new API.ChatKit(this), }; + analytics = new API.Analytics(this); post = ( url: string, diff --git a/src/utils.ts b/src/utils.ts index f5347a5..6269021 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -19,6 +19,7 @@ import { ApiKeysListParams } from './apis/apiKeys'; import { CongfigsListParams } from './apis/configs'; import { LogsExportListParams } from './apis/logsExport'; import { getBrowserInfo } from './core'; +import { AnalyticsBaseParams } from './apis/analytics'; type PlatformProperties = { 'x-portkey-runtime'?: string; @@ -219,17 +220,18 @@ export function toQueryParams( | ApiKeysListParams | CongfigsListParams | LogsExportListParams + | AnalyticsBaseParams | any ): string { if (!params) { return ''; } - const queryParams = Object.entries(params) - .filter(([, value]) => value !== undefined && value !== null) - .map(([key, value]) => `${key}=${value}`) - .join('&'); - - return queryParams ? `?${queryParams}` : ''; + const search = new URLSearchParams(); + for (const [key, value] of Object.entries(params)) { + if (value !== undefined && value !== null) + search.append(key, String(value)); + } + return search.toString() ? `?${search.toString()}` : ''; } export function setBaseURL(baseURL: any, apiKey: any) { diff --git a/src/version.ts b/src/version.ts index d847bf1..7af9362 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '3.0.1'; +export const VERSION = '3.0.2'; From c77b3731a48256bc0d6c7c0934ba333842f038bf Mon Sep 17 00:00:00 2001 From: Chandra Kiran G Date: Tue, 14 Apr 2026 16:14:49 +0530 Subject: [PATCH 2/4] fix: Rename body to _query --- src/apis/analytics.ts | 92 +++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/src/apis/analytics.ts b/src/apis/analytics.ts index b4b738a..755db01 100644 --- a/src/apis/analytics.ts +++ b/src/apis/analytics.ts @@ -85,11 +85,11 @@ export class Analytics extends ApiResource { export class AnalyticsGraphs extends ApiResource { requests( - body: AnalyticsGraphsGetParams, + _query: AnalyticsGraphsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -104,11 +104,11 @@ export class AnalyticsGraphs extends ApiResource { } cost( - body: AnalyticsGraphsGetParams, + _query: AnalyticsGraphsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -122,11 +122,11 @@ export class AnalyticsGraphs extends ApiResource { } latency( - body: AnalyticsGraphsGetParams, + _query: AnalyticsGraphsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -140,11 +140,11 @@ export class AnalyticsGraphs extends ApiResource { } tokens( - body: AnalyticsGraphsGetParams, + _query: AnalyticsGraphsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -158,11 +158,11 @@ export class AnalyticsGraphs extends ApiResource { } users( - body: AnalyticsGraphsGetParams, + _query: AnalyticsGraphsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -176,11 +176,11 @@ export class AnalyticsGraphs extends ApiResource { } usersRequests( - body: AnalyticsGraphsGetParams, + _query: AnalyticsGraphsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -197,11 +197,11 @@ export class AnalyticsGraphs extends ApiResource { } errors( - body: AnalyticsGraphsGetParams, + _query: AnalyticsGraphsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -215,11 +215,11 @@ export class AnalyticsGraphs extends ApiResource { } errors_rate( - body: AnalyticsGraphsGetParams, + _query: AnalyticsGraphsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -236,11 +236,11 @@ export class AnalyticsGraphs extends ApiResource { } errors_stack( - body: AnalyticsGraphsGetParams, + _query: AnalyticsGraphsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -257,11 +257,11 @@ export class AnalyticsGraphs extends ApiResource { } errors_status_code( - body: AnalyticsGraphsGetParams, + _query: AnalyticsGraphsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -278,11 +278,11 @@ export class AnalyticsGraphs extends ApiResource { } requests_rescued( - body: AnalyticsGraphsGetParams, + _query: AnalyticsGraphsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -299,11 +299,11 @@ export class AnalyticsGraphs extends ApiResource { } cache_hit_rate( - body: AnalyticsGraphsGetParams, + _query: AnalyticsGraphsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -320,11 +320,11 @@ export class AnalyticsGraphs extends ApiResource { } cache_latency( - body: AnalyticsGraphsGetParams, + _query: AnalyticsGraphsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -341,11 +341,11 @@ export class AnalyticsGraphs extends ApiResource { } feedbacks( - body: AnalyticsGraphsGetParams, + _query: AnalyticsGraphsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -362,11 +362,11 @@ export class AnalyticsGraphs extends ApiResource { } feedbacks_score( - body: AnalyticsGraphsGetParams, + _query: AnalyticsGraphsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { @@ -386,11 +386,11 @@ export class AnalyticsGraphs extends ApiResource { } feedbacks_weighted( - body: AnalyticsGraphsGetParams, + _query: AnalyticsGraphsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { @@ -409,11 +409,11 @@ export class AnalyticsGraphs extends ApiResource { } feedback_ai_models( - body: AnalyticsGraphsGetParams, + _query: AnalyticsGraphsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { @@ -434,11 +434,11 @@ export class AnalyticsGraphs extends ApiResource { export class AnalyticsGroups extends ApiResource { users( - body: AnalyticsGroupsGetParams, + _query: AnalyticsGroupsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -452,11 +452,11 @@ export class AnalyticsGroups extends ApiResource { } aiModels( - body: AnalyticsGroupsGetParams, + _query: AnalyticsGroupsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -473,11 +473,11 @@ export class AnalyticsGroups extends ApiResource { } workspaces( - body: AnalyticsGroupsGetParams, + _query: AnalyticsGroupsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -495,11 +495,11 @@ export class AnalyticsGroups extends ApiResource { metadata( metadataKey: string, - body: AnalyticsGroupsGetParams, + _query: AnalyticsGroupsGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -517,11 +517,11 @@ export class AnalyticsGroups extends ApiResource { groupedData( groupBy: AnalyticsGroupByValue, - body: AnalyticsGroupedDataParams, + _query: AnalyticsGroupedDataParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, @@ -540,11 +540,11 @@ export class AnalyticsGroups extends ApiResource { export class AnalyticsSummary extends ApiResource { cache( - body: AnalyticsSummaryGetParams, + _query: AnalyticsSummaryGetParams, params?: ApiClientInterface, opts?: RequestOptions ): APIPromise { - const queryParams = toQueryParams(body); + const queryParams = toQueryParams(_query); if (params) { this.client.customHeaders = { ...this.client.customHeaders, From 952bbf860b63f4d3eddf04a0a8ada885991f1a1f Mon Sep 17 00:00:00 2001 From: Chandra Kiran G Date: Tue, 14 Apr 2026 17:08:57 +0530 Subject: [PATCH 3/4] feat: Add MCP APIs --- src/apis/index.ts | 2 + src/apis/mcpIntegrations.ts | 406 +++++++++++++++++++++++++ src/apis/mcpServers.ts | 580 ++++++++++++++++++++++++++++++++++++ src/client.ts | 2 + 4 files changed, 990 insertions(+) create mode 100644 src/apis/mcpIntegrations.ts create mode 100644 src/apis/mcpServers.ts diff --git a/src/apis/index.ts b/src/apis/index.ts index f8eabf2..00b9e27 100644 --- a/src/apis/index.ts +++ b/src/apis/index.ts @@ -39,3 +39,5 @@ export { Videos } from './videos'; export { ChatKit } from './chatkit'; export { Guardrails } from './guardrails'; export { Analytics } from './analytics'; +export { MCPIntegrations } from './mcpIntegrations'; +export { MCPServers } from './mcpServers'; diff --git a/src/apis/mcpIntegrations.ts b/src/apis/mcpIntegrations.ts new file mode 100644 index 0000000..fe1efb8 --- /dev/null +++ b/src/apis/mcpIntegrations.ts @@ -0,0 +1,406 @@ +import { ApiClientInterface, APIResponseType } from '../_types/generalTypes'; +import { ApiResource } from '../apiResource'; +import { APIPromise, RequestOptions } from '../baseClient'; +import { createHeaders } from './createHeaders'; +import { toQueryParams } from '../utils'; + +export type MCPIntegrationAuthType = + | 'oauth_auto' + | 'oauth_client_credentials' + | 'headers' + | 'none'; + +export type MCPIntegrationTransport = 'http' | 'sse'; + +export interface MCPIntegrationsCreateParams { + name: string; + url: string; + auth_type: MCPIntegrationAuthType; + transport: MCPIntegrationTransport; + workspace_id?: string; + organisation_id?: string; + slug?: string; + description?: string | null; + configurations?: Record; +} + +export interface MCPIntegrationsCreateResponse extends APIResponseType { + id?: string; + slug?: string; +} + +export interface MCPIntegrationsListParams { + organisation_id?: string; + workspace_id?: string; + type?: 'workspace' | 'organisation' | 'all'; + page_size?: number; + current_page?: number; + search?: string; +} + +export interface MCPIntegrationData extends APIResponseType { + id?: string; + slug?: string; + name?: string; + description?: string | null; + url?: string; + auth_type?: MCPIntegrationAuthType; + transport?: MCPIntegrationTransport; + configurations?: Record; + workspace_id?: string | null; + organisation_id?: string; + owner_id?: string; + created_at?: string; + updated_at?: string; +} + +export interface MCPIntegrationsListResponse extends APIResponseType { + data?: MCPIntegrationData[]; + total?: number; +} + +export interface MCPIntegrationsRetrieveParams { + id: string; +} + +export interface MCPIntegrationsUpdateParams { + id: string; + name?: string; + description?: string | null; + url?: string; + auth_type?: MCPIntegrationAuthType; + transport?: MCPIntegrationTransport; + configurations?: Record; +} + +export interface MCPIntegrationsUpdateResponse extends APIResponseType { + id?: string; + slug?: string; +} + +export interface MCPIntegrationsDeleteParams { + id: string; +} + +export interface MCPIntegrationsSyncParams { + id: string; + server_info?: { + name?: string; + version?: string; + title?: string; + description?: string; + website_url?: string; + icons?: any[]; + protocol_version?: string; + capabilities?: Record; + instructions?: string; + }; + capabilities?: Array<{ + name?: string; + type?: 'tool' | 'prompt' | 'resource' | 'resource_template'; + title?: string; + description?: string; + icons?: any[]; + _meta?: Record; + input_schema?: Record; + inputSchema?: Record; + output_schema?: Record; + outputSchema?: Record; + execution?: Record; + annotations?: Record; + arguments?: any[]; + uri?: string; + mime_type?: string; + mimeType?: string; + size?: number; + uri_template?: string; + uriTemplate?: string; + }>; +} + +export interface MCPIntegrationsTestParams { + id: string; +} + +export interface MCPIntegrationsWorkspacesListParams { + id: string; +} + +export interface MCPIntegrationsWorkspacesUpdateParams { + id: string; + workspaces: Array<{ + id: string; + enabled: boolean; + }>; + global_workspace_access?: { + enabled: boolean; + } | null; + override_existing_workspace_access?: boolean; +} + +export interface MCPIntegrationsCapabilitiesListParams { + id: string; +} + +export interface MCPIntegrationsCapabilitiesUpdateParams { + id: string; + capabilities: Array<{ + name: string; + type: 'tool' | 'prompt' | 'resource'; + enabled: boolean; + }>; +} + +export interface MCPIntegrationsMetadataGetParams { + id: string; +} + +export class MCPIntegrations extends ApiResource { + workspaces: MCPIntegrationsWorkspaces; + capabilities: MCPIntegrationsCapabilities; + metadata: MCPIntegrationsMetadata; + + constructor(client: any) { + super(client); + this.workspaces = new MCPIntegrationsWorkspaces(client); + this.capabilities = new MCPIntegrationsCapabilities(client); + this.metadata = new MCPIntegrationsMetadata(client); + } + + create( + body: MCPIntegrationsCreateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.post( + '/mcp-integrations', + { + body, + ...opts, + } + ); + return response; + } + + list( + _body?: MCPIntegrationsListParams, + 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( + `/mcp-integrations${query}`, + { ...opts } + ); + return response; + } + + retrieve( + body: MCPIntegrationsRetrieveParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-integrations/${id}`, + { ...opts } + ); + return response; + } + + update( + body: MCPIntegrationsUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put( + `/mcp-integrations/${id}`, + { body: restBody, ...opts } + ); + return response; + } + + delete( + body: MCPIntegrationsDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.deleteMethod( + `/mcp-integrations/${id}`, + { ...opts } + ); + return response; + } + + sync( + body: MCPIntegrationsSyncParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.post( + `/mcp-integrations/${id}/sync`, + { body: restBody, ...opts } + ); + return response; + } + + test( + body: MCPIntegrationsTestParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.post( + `/mcp-integrations/${id}/test`, + { body: {}, ...opts } + ); + return response; + } +} + +export class MCPIntegrationsWorkspaces extends ApiResource { + list( + body: MCPIntegrationsWorkspacesListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-integrations/${id}/workspaces`, + { ...opts } + ); + return response; + } + + update( + body: MCPIntegrationsWorkspacesUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put( + `/mcp-integrations/${id}/workspaces`, + { body: restBody, ...opts } + ); + return response; + } +} + +export class MCPIntegrationsCapabilities extends ApiResource { + list( + body: MCPIntegrationsCapabilitiesListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-integrations/${id}/capabilities`, + { ...opts } + ); + return response; + } + + update( + body: MCPIntegrationsCapabilitiesUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put( + `/mcp-integrations/${id}/capabilities`, + { body: restBody, ...opts } + ); + return response; + } +} + +export class MCPIntegrationsMetadata extends ApiResource { + get( + body: MCPIntegrationsMetadataGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-integrations/${id}/metadata`, + { ...opts } + ); + return response; + } +} diff --git a/src/apis/mcpServers.ts b/src/apis/mcpServers.ts new file mode 100644 index 0000000..91c704d --- /dev/null +++ b/src/apis/mcpServers.ts @@ -0,0 +1,580 @@ +import { ApiClientInterface, APIResponseType } from '../_types/generalTypes'; +import { ApiResource } from '../apiResource'; +import { APIPromise, RequestOptions } from '../baseClient'; +import { createHeaders } from './createHeaders'; +import { toQueryParams } from '../utils'; + +export interface MCPServersCreateParams { + name: string; + mcp_integration_id: string; + workspace_id?: string; + description?: string | null; + slug?: string; +} + +export interface MCPServersCreateResponse extends APIResponseType { + id?: string; + slug?: string; +} + +export interface MCPServersListParams { + workspace_id?: string; + current_page?: number; + page_size?: number; + id?: string; + search?: string; +} + +export interface MCPServerMetadata { + title?: string | null; + description?: string | null; + icons?: any[] | null; + server_name?: string | null; + server_version?: string | null; + protocol_version?: string | null; + sync_status?: string; + last_synced_at?: string | null; +} + +export interface MCPServerData extends APIResponseType { + id?: string; + slug?: string; + name?: string; + description?: string | null; + workspace_id?: string; + organisation_id?: string; + mcp_integration_id?: string; + owner_id?: string; + url?: string; + metadata?: MCPServerMetadata; + created_at?: string; + updated_at?: string; +} + +export interface MCPServersListResponse extends APIResponseType { + data?: MCPServerData[]; + total?: number; +} + +export interface MCPServersRetrieveParams { + id: string; +} + +export interface MCPServersUpdateParams { + id: string; + name?: string; + description?: string | null; +} + +export interface MCPServersUpdateResponse extends APIResponseType { + id?: string; + slug?: string; +} + +export interface MCPServersDeleteParams { + id: string; +} + +export interface MCPServersTestParams { + id: string; +} + +export interface MCPServersTokensGetParams { + id: string; +} + +export interface MCPServersTokensSetParams { + id: string; + access_token: string; + refresh_token?: string; +} + +export interface MCPServersTokensDeleteParams { + id: string; +} + +export interface MCPServersClientInfoParams { + id: string; +} + +export interface MCPServerCapability { + name: string; + type: 'tool' | 'prompt' | 'resource'; + enabled?: boolean; + description?: string | null; + schema?: Record | null; +} + +export interface MCPServersCapabilitiesListParams { + id: string; +} + +export interface MCPServersCapabilitiesUpdateParams { + id: string; + capabilities: Array<{ + name: string; + type: 'tool' | 'prompt' | 'resource'; + enabled: boolean; + }>; +} + +export interface MCPServersCapabilitiesSyncParams { + id: string; + capabilities: Array<{ + name: string; + type: 'tool' | 'prompt' | 'resource'; + description?: string | null; + schema?: Record | null; + }>; +} + +export interface MCPServersUserAccessCheckParams { + id: string; +} + +export interface MCPServersUserAccessListParams { + id: string; +} + +export interface MCPServersUserAccessUpdateParams { + id: string; + user_access?: Array<{ + id?: string; + user_id?: string; + enabled: boolean; + }>; + default_user_access?: 'allow' | 'deny'; +} + +export interface MCPServersMetadataGetParams { + id: string; +} + +export interface MCPServersMetadataSyncParams { + id: string; + server_name?: string | null; + server_version?: string | null; + protocol_version?: string | null; + title?: string | null; + description?: string | null; + website_url?: string | null; + icons?: any[] | null; + capability_flags?: Record | null; + instructions?: string | null; +} + +export interface MCPServersConnectionsListParams { + id: string; + user_id?: string; + workspace_id?: string; + current_page?: number; + page_size?: number; +} + +export interface MCPServersConnectionsDeleteParams { + id: string; + user_id?: string; + workspace_id?: string; +} + +export class MCPServers extends ApiResource { + capabilities: MCPServersCapabilities; + userAccess: MCPServersUserAccess; + metadata: MCPServersMetadata; + connections: MCPServersConnections; + + constructor(client: any) { + super(client); + this.capabilities = new MCPServersCapabilities(client); + this.userAccess = new MCPServersUserAccess(client); + this.metadata = new MCPServersMetadata(client); + this.connections = new MCPServersConnections(client); + } + + create( + body: MCPServersCreateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.post('/mcp-servers', { + body, + ...opts, + }); + return response; + } + + list( + _query?: MCPServersListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const query = toQueryParams(_query); + const response = this.getMethod( + `/mcp-servers${query}`, + { ...opts } + ); + return response; + } + + retrieve( + body: MCPServersRetrieveParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`/mcp-servers/${id}`, { + ...opts, + }); + return response; + } + + update( + body: MCPServersUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put(`/mcp-servers/${id}`, { + body: restBody, + ...opts, + }); + return response; + } + + delete( + body: MCPServersDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.deleteMethod(`/mcp-servers/${id}`, { + ...opts, + }); + return response; + } + + test( + body: MCPServersTestParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.post(`/mcp-servers/${id}/test`, { + body: {}, + ...opts, + }); + return response; + } + + getTokens( + body: MCPServersTokensGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-servers/${id}/tokens`, + { ...opts } + ); + return response; + } + + setTokens( + body: MCPServersTokensSetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put(`/mcp-servers/${id}/tokens`, { + body: restBody, + ...opts, + }); + return response; + } + + deleteTokens( + body: MCPServersTokensDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.deleteMethod( + `/mcp-servers/${id}/tokens`, + { ...opts } + ); + return response; + } + + getClientInfo( + body: MCPServersClientInfoParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-servers/${id}/client-info`, + { ...opts } + ); + return response; + } +} + +export class MCPServersCapabilities extends ApiResource { + list( + body: MCPServersCapabilitiesListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-servers/${id}/capabilities`, + { ...opts } + ); + return response; + } + + update( + body: MCPServersCapabilitiesUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put( + `/mcp-servers/${id}/capabilities`, + { body: restBody, ...opts } + ); + return response; + } + + sync( + body: MCPServersCapabilitiesSyncParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.post( + `/mcp-servers/${id}/capabilities/sync`, + { body: restBody, ...opts } + ); + return response; + } +} + +export class MCPServersUserAccess extends ApiResource { + check( + body: MCPServersUserAccessCheckParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-servers/${id}/user-access/check`, + { ...opts } + ); + return response; + } + + list( + body: MCPServersUserAccessListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-servers/${id}/user-access`, + { ...opts } + ); + return response; + } + + update( + body: MCPServersUserAccessUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put( + `/mcp-servers/${id}/user-access`, + { body: restBody, ...opts } + ); + return response; + } +} + +export class MCPServersMetadata extends ApiResource { + get( + body: MCPServersMetadataGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-servers/${id}/metadata`, + { ...opts } + ); + return response; + } + + sync( + body: MCPServersMetadataSyncParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.post( + `/mcp-servers/${id}/metadata/sync`, + { body: restBody, ...opts } + ); + return response; + } +} + +export class MCPServersConnections extends ApiResource { + list( + body: MCPServersConnectionsListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...queryParams } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const query = toQueryParams(queryParams); + const response = this.getMethod( + `/mcp-servers/${id}/connections${query}`, + { ...opts } + ); + return response; + } + + delete( + body: MCPServersConnectionsDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...queryParams } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const query = toQueryParams(queryParams); + const response = this.deleteMethod( + `/mcp-servers/${id}/connections${query}`, + { ...opts } + ); + return response; + } +} diff --git a/src/client.ts b/src/client.ts index f2fefa9..e1fa778 100644 --- a/src/client.ts +++ b/src/client.ts @@ -224,6 +224,8 @@ export class Portkey extends ApiClient { chatkit: new API.ChatKit(this), }; analytics = new API.Analytics(this); + mcpServers = new API.MCPServers(this); + mcpIntegrations = new API.MCPIntegrations(this); post = ( url: string, From 7291fa5dbf27a875619a832bf485313e05c874de Mon Sep 17 00:00:00 2001 From: Chandra Kiran G Date: Wed, 15 Apr 2026 19:52:05 +0530 Subject: [PATCH 4/4] chore: Do not bump version --- src/version.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.ts b/src/version.ts index 7af9362..d847bf1 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '3.0.2'; +export const VERSION = '3.0.1';