// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../core/resource'; import { APIPromise } from '../../core/api-promise'; import { PagePromise, V4PagePaginationArray, type V4PagePaginationArrayParams } from '../../core/pagination'; import { RequestOptions } from '../../internal/request-options'; import { path } from '../../internal/utils/path'; export class BaseDatasets extends APIResource { static override readonly _key: readonly ['aiGateway', 'datasets'] = Object.freeze([ 'aiGateway', 'datasets', ] as const); /** * Creates a new AI Gateway. * * @example * ```ts * const dataset = await client.aiGateway.datasets.create( * 'my-gateway', * { * account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', * enable: true, * filters: [ * { * key: 'created_at', * operator: 'eq', * value: ['string'], * }, * ], * name: 'name', * }, * ); * ``` */ create( gatewayID: string, params: DatasetCreateParams, options?: RequestOptions, ): APIPromise { const { account_id, ...body } = params; return ( this._client.post(path`/accounts/${account_id}/ai-gateway/gateways/${gatewayID}/datasets`, { body, ...options, }) as APIPromise<{ result: DatasetCreateResponse }> )._thenUnwrap((obj) => obj.result); } /** * Updates an existing AI Gateway dataset. * * @example * ```ts * const dataset = await client.aiGateway.datasets.update( * 'id', * { * account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', * gateway_id: 'my-gateway', * enable: true, * filters: [ * { * key: 'created_at', * operator: 'eq', * value: ['string'], * }, * ], * name: 'name', * }, * ); * ``` */ update( id: string, params: DatasetUpdateParams, options?: RequestOptions, ): APIPromise { const { account_id, gateway_id, ...body } = params; return ( this._client.put(path`/accounts/${account_id}/ai-gateway/gateways/${gateway_id}/datasets/${id}`, { body, ...options, }) as APIPromise<{ result: DatasetUpdateResponse }> )._thenUnwrap((obj) => obj.result); } /** * Lists all AI Gateway evaluator types configured for the account. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const datasetListResponse of client.aiGateway.datasets.list( * 'my-gateway', * { account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0' }, * )) { * // ... * } * ``` */ list( gatewayID: string, params: DatasetListParams, options?: RequestOptions, ): PagePromise { const { account_id, ...query } = params; return this._client.getAPIList( path`/accounts/${account_id}/ai-gateway/gateways/${gatewayID}/datasets`, V4PagePaginationArray, { query, ...options }, ); } /** * Deletes an AI Gateway dataset. * * @example * ```ts * const dataset = await client.aiGateway.datasets.delete( * 'id', * { * account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', * gateway_id: 'my-gateway', * }, * ); * ``` */ delete( id: string, params: DatasetDeleteParams, options?: RequestOptions, ): APIPromise { const { account_id, gateway_id } = params; return ( this._client.delete( path`/accounts/${account_id}/ai-gateway/gateways/${gateway_id}/datasets/${id}`, options, ) as APIPromise<{ result: DatasetDeleteResponse }> )._thenUnwrap((obj) => obj.result); } /** * Retrieves details for a specific AI Gateway dataset. * * @example * ```ts * const dataset = await client.aiGateway.datasets.get('id', { * account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0', * gateway_id: 'my-gateway', * }); * ``` */ get(id: string, params: DatasetGetParams, options?: RequestOptions): APIPromise { const { account_id, gateway_id } = params; return ( this._client.get( path`/accounts/${account_id}/ai-gateway/gateways/${gateway_id}/datasets/${id}`, options, ) as APIPromise<{ result: DatasetGetResponse }> )._thenUnwrap((obj) => obj.result); } } export class Datasets extends BaseDatasets {} export type DatasetListResponsesV4PagePaginationArray = V4PagePaginationArray; export interface DatasetCreateResponse { id: string; created_at: string; enable: boolean; filters: Array; /** * gateway id */ gateway_id: string; modified_at: string; name: string; } export namespace DatasetCreateResponse { export interface Filter { key: | 'created_at' | 'request_content_type' | 'response_content_type' | 'success' | 'cached' | 'provider' | 'model' | 'cost' | 'tokens' | 'tokens_in' | 'tokens_out' | 'duration' | 'feedback'; operator: 'eq' | 'contains' | 'lt' | 'gt'; value: Array; } } export interface DatasetUpdateResponse { id: string; created_at: string; enable: boolean; filters: Array; /** * gateway id */ gateway_id: string; modified_at: string; name: string; } export namespace DatasetUpdateResponse { export interface Filter { key: | 'created_at' | 'request_content_type' | 'response_content_type' | 'success' | 'cached' | 'provider' | 'model' | 'cost' | 'tokens' | 'tokens_in' | 'tokens_out' | 'duration' | 'feedback'; operator: 'eq' | 'contains' | 'lt' | 'gt'; value: Array; } } export interface DatasetListResponse { id: string; created_at: string; enable: boolean; filters: Array; /** * gateway id */ gateway_id: string; modified_at: string; name: string; } export namespace DatasetListResponse { export interface Filter { key: | 'created_at' | 'request_content_type' | 'response_content_type' | 'success' | 'cached' | 'provider' | 'model' | 'cost' | 'tokens' | 'tokens_in' | 'tokens_out' | 'duration' | 'feedback'; operator: 'eq' | 'contains' | 'lt' | 'gt'; value: Array; } } export interface DatasetDeleteResponse { id: string; created_at: string; enable: boolean; filters: Array; /** * gateway id */ gateway_id: string; modified_at: string; name: string; } export namespace DatasetDeleteResponse { export interface Filter { key: | 'created_at' | 'request_content_type' | 'response_content_type' | 'success' | 'cached' | 'provider' | 'model' | 'cost' | 'tokens' | 'tokens_in' | 'tokens_out' | 'duration' | 'feedback'; operator: 'eq' | 'contains' | 'lt' | 'gt'; value: Array; } } export interface DatasetGetResponse { id: string; created_at: string; enable: boolean; filters: Array; /** * gateway id */ gateway_id: string; modified_at: string; name: string; } export namespace DatasetGetResponse { export interface Filter { key: | 'created_at' | 'request_content_type' | 'response_content_type' | 'success' | 'cached' | 'provider' | 'model' | 'cost' | 'tokens' | 'tokens_in' | 'tokens_out' | 'duration' | 'feedback'; operator: 'eq' | 'contains' | 'lt' | 'gt'; value: Array; } } export interface DatasetCreateParams { /** * Path param */ account_id: string; /** * Body param */ enable: boolean; /** * Body param */ filters: Array; /** * Body param */ name: string; } export namespace DatasetCreateParams { export interface Filter { key: | 'created_at' | 'request_content_type' | 'response_content_type' | 'success' | 'cached' | 'provider' | 'model' | 'cost' | 'tokens' | 'tokens_in' | 'tokens_out' | 'duration' | 'feedback'; operator: 'eq' | 'contains' | 'lt' | 'gt'; value: Array; } } export interface DatasetUpdateParams { /** * Path param */ account_id: string; /** * Path param: gateway id */ gateway_id: string; /** * Body param */ enable: boolean; /** * Body param */ filters: Array; /** * Body param */ name: string; } export namespace DatasetUpdateParams { export interface Filter { key: | 'created_at' | 'request_content_type' | 'response_content_type' | 'success' | 'cached' | 'provider' | 'model' | 'cost' | 'tokens' | 'tokens_in' | 'tokens_out' | 'duration' | 'feedback'; operator: 'eq' | 'contains' | 'lt' | 'gt'; value: Array; } } export interface DatasetListParams extends V4PagePaginationArrayParams { /** * Path param */ account_id: string; /** * Query param */ enable?: boolean; /** * Query param */ name?: string; /** * Query param: Search by id, name, filters */ search?: string; } export interface DatasetDeleteParams { account_id: string; /** * gateway id */ gateway_id: string; } export interface DatasetGetParams { account_id: string; /** * gateway id */ gateway_id: string; } export declare namespace Datasets { export { type DatasetCreateResponse as DatasetCreateResponse, type DatasetUpdateResponse as DatasetUpdateResponse, type DatasetListResponse as DatasetListResponse, type DatasetDeleteResponse as DatasetDeleteResponse, type DatasetGetResponse as DatasetGetResponse, type DatasetListResponsesV4PagePaginationArray as DatasetListResponsesV4PagePaginationArray, type DatasetCreateParams as DatasetCreateParams, type DatasetUpdateParams as DatasetUpdateParams, type DatasetListParams as DatasetListParams, type DatasetDeleteParams as DatasetDeleteParams, type DatasetGetParams as DatasetGetParams, }; }