UNPKG

openpipe

Version:

OpenPipe TypeScript SDK: Fine-Tuning, Inference, and Metrics for Production Apps

1 lines 85.6 kB
{"version":3,"sources":["../src/client.ts","../src/codegen/core/BaseHttpRequest.ts","../src/codegen/core/request.ts","../src/codegen/core/ApiError.ts","../src/codegen/core/CancelablePromise.ts","../src/codegen/core/NodeHttpRequest.ts","../src/codegen/services/DefaultService.ts","../src/codegen/OPClient.ts","../src/helpers.ts"],"sourcesContent":["import { OPClient } from \"./codegen\";\nimport { readEnv } from \"./helpers\";\nimport { OpenPipeConfig } from \"./shared\";\n\nexport default class OpenPipe {\n baseClient: OPClient;\n\n constructor(config: OpenPipeConfig = {}) {\n const openPipeApiKey = config?.apiKey ?? readEnv(\"OPENPIPE_API_KEY\");\n const openpipeBaseUrl = config?.baseUrl ?? readEnv(\"OPENPIPE_BASE_URL\");\n\n this.baseClient = new OPClient({\n BASE: openpipeBaseUrl,\n TOKEN: openPipeApiKey,\n });\n }\n\n updateLogTags(...params: Parameters<OPClient[\"default\"][\"updateLogTags\"]>) {\n return this.baseClient.default.updateLogTags(...params);\n }\n\n updateLogMetadata(...params: Parameters<OPClient[\"default\"][\"updateLogMetadata\"]>) {\n return this.baseClient.default.updateLogMetadata(...params);\n }\n\n report(...params: Parameters<OPClient[\"default\"][\"report\"]>) {\n return this.baseClient.default.report(...params);\n }\n\n getCriterionJudgement(...params: Parameters<OPClient[\"default\"][\"getCriterionJudgement\"]>) {\n return this.baseClient.default.getCriterionJudgement(...params);\n }\n\n reportAnthropic(...params: Parameters<OPClient[\"default\"][\"reportAnthropic\"]>) {\n return this.baseClient.default.reportAnthropic(...params);\n }\n\n createDataset(...params: Parameters<OPClient[\"default\"][\"createDataset\"]>) {\n return this.baseClient.default.createDataset(...params);\n }\n unstableDatasetCreate(...params: Parameters<OPClient[\"default\"][\"unstableDatasetCreate\"]>) {\n return this.baseClient.default.unstableDatasetCreate(...params);\n }\n\n listDatasets(...params: Parameters<OPClient[\"default\"][\"listDatasets\"]>) {\n return this.baseClient.default.listDatasets(...params);\n }\n\n deleteDataset(...params: Parameters<OPClient[\"default\"][\"deleteDataset\"]>) {\n return this.baseClient.default.deleteDataset(...params);\n }\n unstableDatasetDelete(...params: Parameters<OPClient[\"default\"][\"unstableDatasetDelete\"]>) {\n return this.baseClient.default.unstableDatasetDelete(...params);\n }\n\n createDatasetEntries(...params: Parameters<OPClient[\"default\"][\"createDatasetEntries\"]>) {\n return this.baseClient.default.createDatasetEntries(...params);\n }\n unstableDatasetEntryCreate(\n ...params: Parameters<OPClient[\"default\"][\"unstableDatasetEntryCreate\"]>\n ) {\n return this.baseClient.default.unstableDatasetEntryCreate(...params);\n }\n\n createModel(...params: Parameters<OPClient[\"default\"][\"createModel\"]>) {\n return this.baseClient.default.createModel(...params);\n }\n unstableFinetuneCreate(...params: Parameters<OPClient[\"default\"][\"unstableFinetuneCreate\"]>) {\n return this.baseClient.default.unstableFinetuneCreate(...params);\n }\n\n getModel(...params: Parameters<OPClient[\"default\"][\"getModel\"]>) {\n return this.baseClient.default.getModel(...params);\n }\n unstableFinetuneGet(...params: Parameters<OPClient[\"default\"][\"unstableFinetuneGet\"]>) {\n return this.baseClient.default.unstableFinetuneGet(...params);\n }\n\n listModels(...params: Parameters<OPClient[\"default\"][\"listModels\"]>) {\n return this.baseClient.default.listModels(...params);\n }\n\n deleteModel(...params: Parameters<OPClient[\"default\"][\"deleteModel\"]>) {\n return this.baseClient.default.deleteModel(...params);\n }\n unstableFinetuneDelete(...params: Parameters<OPClient[\"default\"][\"unstableFinetuneDelete\"]>) {\n return this.baseClient.default.unstableFinetuneDelete(...params);\n }\n}\n","/* generated using openapi-typescript-codegen -- do no edit */\n/* istanbul ignore file */\n/* tslint:disable */\n/* eslint-disable */\nimport type { ApiRequestOptions } from './ApiRequestOptions';\nimport type { CancelablePromise } from './CancelablePromise';\nimport type { OpenAPIConfig } from './OpenAPI';\n\nexport abstract class BaseHttpRequest {\n\n constructor(public readonly config: OpenAPIConfig) {}\n\n public abstract request<T>(options: ApiRequestOptions): CancelablePromise<T>;\n}\n","/* generated using openapi-typescript-codegen -- do no edit */\n/* istanbul ignore file */\n/* tslint:disable */\n/* eslint-disable */\nimport FormData from 'form-data';\nimport fetch, { Headers } from 'node-fetch';\nimport type { RequestInit, Response } from 'node-fetch';\nimport type { AbortSignal } from 'node-fetch/externals';\n\nimport { ApiError } from './ApiError';\nimport type { ApiRequestOptions } from './ApiRequestOptions';\nimport type { ApiResult } from './ApiResult';\nimport { CancelablePromise } from './CancelablePromise';\nimport type { OnCancel } from './CancelablePromise';\nimport type { OpenAPIConfig } from './OpenAPI';\n\nexport const isDefined = <T>(value: T | null | undefined): value is Exclude<T, null | undefined> => {\n return value !== undefined && value !== null;\n};\n\nexport const isString = (value: any): value is string => {\n return typeof value === 'string';\n};\n\nexport const isStringWithValue = (value: any): value is string => {\n return isString(value) && value !== '';\n};\n\nexport const isBlob = (value: any): value is Blob => {\n return (\n typeof value === 'object' &&\n typeof value.type === 'string' &&\n typeof value.stream === 'function' &&\n typeof value.arrayBuffer === 'function' &&\n typeof value.constructor === 'function' &&\n typeof value.constructor.name === 'string' &&\n /^(Blob|File)$/.test(value.constructor.name) &&\n /^(Blob|File)$/.test(value[Symbol.toStringTag])\n );\n};\n\nexport const isFormData = (value: any): value is FormData => {\n return value instanceof FormData;\n};\n\nexport const base64 = (str: string): string => {\n try {\n return btoa(str);\n } catch (err) {\n // @ts-ignore\n return Buffer.from(str).toString('base64');\n }\n};\n\nexport const getQueryString = (params: Record<string, any>): string => {\n const qs: string[] = [];\n\n const append = (key: string, value: any) => {\n qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);\n };\n\n const process = (key: string, value: any) => {\n if (isDefined(value)) {\n if (Array.isArray(value)) {\n value.forEach(v => {\n process(key, v);\n });\n } else if (typeof value === 'object') {\n Object.entries(value).forEach(([k, v]) => {\n process(`${key}[${k}]`, v);\n });\n } else {\n append(key, value);\n }\n }\n };\n\n Object.entries(params).forEach(([key, value]) => {\n process(key, value);\n });\n\n if (qs.length > 0) {\n return `?${qs.join('&')}`;\n }\n\n return '';\n};\n\nconst getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => {\n const encoder = config.ENCODE_PATH || encodeURI;\n\n const path = options.url\n .replace('{api-version}', config.VERSION)\n .replace(/{(.*?)}/g, (substring: string, group: string) => {\n if (options.path?.hasOwnProperty(group)) {\n return encoder(String(options.path[group]));\n }\n return substring;\n });\n\n const url = `${config.BASE}${path}`;\n if (options.query) {\n return `${url}${getQueryString(options.query)}`;\n }\n return url;\n};\n\nexport const getFormData = (options: ApiRequestOptions): FormData | undefined => {\n if (options.formData) {\n const formData = new FormData();\n\n const process = (key: string, value: any) => {\n if (isString(value) || isBlob(value)) {\n formData.append(key, value);\n } else {\n formData.append(key, JSON.stringify(value));\n }\n };\n\n Object.entries(options.formData)\n .filter(([_, value]) => isDefined(value))\n .forEach(([key, value]) => {\n if (Array.isArray(value)) {\n value.forEach(v => process(key, v));\n } else {\n process(key, value);\n }\n });\n\n return formData;\n }\n return undefined;\n};\n\ntype Resolver<T> = (options: ApiRequestOptions) => Promise<T>;\n\nexport const resolve = async <T>(options: ApiRequestOptions, resolver?: T | Resolver<T>): Promise<T | undefined> => {\n if (typeof resolver === 'function') {\n return (resolver as Resolver<T>)(options);\n }\n return resolver;\n};\n\nexport const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise<Headers> => {\n const token = await resolve(options, config.TOKEN);\n const username = await resolve(options, config.USERNAME);\n const password = await resolve(options, config.PASSWORD);\n const additionalHeaders = await resolve(options, config.HEADERS);\n\n const headers = Object.entries({\n Accept: 'application/json',\n ...additionalHeaders,\n ...options.headers,\n })\n .filter(([_, value]) => isDefined(value))\n .reduce((headers, [key, value]) => ({\n ...headers,\n [key]: String(value),\n }), {} as Record<string, string>);\n\n if (isStringWithValue(token)) {\n headers['Authorization'] = `Bearer ${token}`;\n }\n\n if (isStringWithValue(username) && isStringWithValue(password)) {\n const credentials = base64(`${username}:${password}`);\n headers['Authorization'] = `Basic ${credentials}`;\n }\n\n if (options.body) {\n if (options.mediaType) {\n headers['Content-Type'] = options.mediaType;\n } else if (isBlob(options.body)) {\n headers['Content-Type'] = 'application/octet-stream';\n } else if (isString(options.body)) {\n headers['Content-Type'] = 'text/plain';\n } else if (!isFormData(options.body)) {\n headers['Content-Type'] = 'application/json';\n }\n }\n\n return new Headers(headers);\n};\n\nexport const getRequestBody = (options: ApiRequestOptions): any => {\n if (options.body !== undefined) {\n if (options.mediaType?.includes('/json')) {\n return JSON.stringify(options.body)\n } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {\n return options.body as any;\n } else {\n return JSON.stringify(options.body);\n }\n }\n return undefined;\n};\n\nexport const sendRequest = async (\n options: ApiRequestOptions,\n url: string,\n body: any,\n formData: FormData | undefined,\n headers: Headers,\n onCancel: OnCancel\n): Promise<Response> => {\n const controller = new AbortController();\n\n const request: RequestInit = {\n headers,\n method: options.method,\n body: body ?? formData,\n signal: controller.signal as AbortSignal,\n };\n\n onCancel(() => controller.abort());\n\n return await fetch(url, request);\n};\n\nexport const getResponseHeader = (response: Response, responseHeader?: string): string | undefined => {\n if (responseHeader) {\n const content = response.headers.get(responseHeader);\n if (isString(content)) {\n return content;\n }\n }\n return undefined;\n};\n\nexport const getResponseBody = async (response: Response): Promise<any> => {\n if (response.status !== 204) {\n try {\n const contentType = response.headers.get('Content-Type');\n if (contentType) {\n const jsonTypes = ['application/json', 'application/problem+json']\n const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));\n if (isJSON) {\n return await response.json();\n } else {\n return await response.text();\n }\n }\n } catch (error) {\n console.error(error);\n }\n }\n return undefined;\n};\n\nexport const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => {\n const errors: Record<number, string> = {\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 403: 'Forbidden',\n 404: 'Not Found',\n 500: 'Internal Server Error',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n ...options.errors,\n }\n\n const error = errors[result.status];\n if (error) {\n throw new ApiError(options, result, error);\n }\n\n if (!result.ok) {\n const errorStatus = result.status ?? 'unknown';\n const errorStatusText = result.statusText ?? 'unknown';\n const errorBody = (() => {\n try {\n return JSON.stringify(result.body, null, 2);\n } catch (e) {\n return undefined;\n }\n })();\n\n throw new ApiError(options, result,\n `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`\n );\n }\n};\n\n/**\n * Request method\n * @param config The OpenAPI configuration object\n * @param options The request options from the service\n * @returns CancelablePromise<T>\n * @throws ApiError\n */\nexport const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise<T> => {\n return new CancelablePromise(async (resolve, reject, onCancel) => {\n try {\n const url = getUrl(config, options);\n const formData = getFormData(options);\n const body = getRequestBody(options);\n const headers = await getHeaders(config, options);\n\n if (!onCancel.isCancelled) {\n const response = await sendRequest(options, url, body, formData, headers, onCancel);\n const responseBody = await getResponseBody(response);\n const responseHeader = getResponseHeader(response, options.responseHeader);\n\n const result: ApiResult = {\n url,\n ok: response.ok,\n status: response.status,\n statusText: response.statusText,\n body: responseHeader ?? responseBody,\n };\n\n catchErrorCodes(options, result);\n\n resolve(result.body);\n }\n } catch (error) {\n reject(error);\n }\n });\n};\n","/* generated using openapi-typescript-codegen -- do no edit */\n/* istanbul ignore file */\n/* tslint:disable */\n/* eslint-disable */\nimport type { ApiRequestOptions } from './ApiRequestOptions';\nimport type { ApiResult } from './ApiResult';\n\nexport class ApiError extends Error {\n public readonly url: string;\n public readonly status: number;\n public readonly statusText: string;\n public readonly body: any;\n public readonly request: ApiRequestOptions;\n\n constructor(request: ApiRequestOptions, response: ApiResult, message: string) {\n super(message);\n\n this.name = 'ApiError';\n this.url = response.url;\n this.status = response.status;\n this.statusText = response.statusText;\n this.body = response.body;\n this.request = request;\n }\n}\n","/* generated using openapi-typescript-codegen -- do no edit */\n/* istanbul ignore file */\n/* tslint:disable */\n/* eslint-disable */\nexport class CancelError extends Error {\n\n constructor(message: string) {\n super(message);\n this.name = 'CancelError';\n }\n\n public get isCancelled(): boolean {\n return true;\n }\n}\n\nexport interface OnCancel {\n readonly isResolved: boolean;\n readonly isRejected: boolean;\n readonly isCancelled: boolean;\n\n (cancelHandler: () => void): void;\n}\n\nexport class CancelablePromise<T> implements Promise<T> {\n #isResolved: boolean;\n #isRejected: boolean;\n #isCancelled: boolean;\n readonly #cancelHandlers: (() => void)[];\n readonly #promise: Promise<T>;\n #resolve?: (value: T | PromiseLike<T>) => void;\n #reject?: (reason?: any) => void;\n\n constructor(\n executor: (\n resolve: (value: T | PromiseLike<T>) => void,\n reject: (reason?: any) => void,\n onCancel: OnCancel\n ) => void\n ) {\n this.#isResolved = false;\n this.#isRejected = false;\n this.#isCancelled = false;\n this.#cancelHandlers = [];\n this.#promise = new Promise<T>((resolve, reject) => {\n this.#resolve = resolve;\n this.#reject = reject;\n\n const onResolve = (value: T | PromiseLike<T>): void => {\n if (this.#isResolved || this.#isRejected || this.#isCancelled) {\n return;\n }\n this.#isResolved = true;\n if (this.#resolve) this.#resolve(value);\n };\n\n const onReject = (reason?: any): void => {\n if (this.#isResolved || this.#isRejected || this.#isCancelled) {\n return;\n }\n this.#isRejected = true;\n if (this.#reject) this.#reject(reason);\n };\n\n const onCancel = (cancelHandler: () => void): void => {\n if (this.#isResolved || this.#isRejected || this.#isCancelled) {\n return;\n }\n this.#cancelHandlers.push(cancelHandler);\n };\n\n Object.defineProperty(onCancel, 'isResolved', {\n get: (): boolean => this.#isResolved,\n });\n\n Object.defineProperty(onCancel, 'isRejected', {\n get: (): boolean => this.#isRejected,\n });\n\n Object.defineProperty(onCancel, 'isCancelled', {\n get: (): boolean => this.#isCancelled,\n });\n\n return executor(onResolve, onReject, onCancel as OnCancel);\n });\n }\n\n get [Symbol.toStringTag]() {\n return \"Cancellable Promise\";\n }\n\n public then<TResult1 = T, TResult2 = never>(\n onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,\n onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null\n ): Promise<TResult1 | TResult2> {\n return this.#promise.then(onFulfilled, onRejected);\n }\n\n public catch<TResult = never>(\n onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null\n ): Promise<T | TResult> {\n return this.#promise.catch(onRejected);\n }\n\n public finally(onFinally?: (() => void) | null): Promise<T> {\n return this.#promise.finally(onFinally);\n }\n\n public cancel(): void {\n if (this.#isResolved || this.#isRejected || this.#isCancelled) {\n return;\n }\n this.#isCancelled = true;\n if (this.#cancelHandlers.length) {\n try {\n for (const cancelHandler of this.#cancelHandlers) {\n cancelHandler();\n }\n } catch (error) {\n console.warn('Cancellation threw an error', error);\n return;\n }\n }\n this.#cancelHandlers.length = 0;\n if (this.#reject) this.#reject(new CancelError('Request aborted'));\n }\n\n public get isCancelled(): boolean {\n return this.#isCancelled;\n }\n}\n","/* generated using openapi-typescript-codegen -- do no edit */\n/* istanbul ignore file */\n/* tslint:disable */\n/* eslint-disable */\nimport type { ApiRequestOptions } from './ApiRequestOptions';\nimport { BaseHttpRequest } from './BaseHttpRequest';\nimport type { CancelablePromise } from './CancelablePromise';\nimport type { OpenAPIConfig } from './OpenAPI';\nimport { request as __request } from './request';\n\nexport class NodeHttpRequest extends BaseHttpRequest {\n\n constructor(config: OpenAPIConfig) {\n super(config);\n }\n\n /**\n * Request method\n * @param options The request options from the service\n * @returns CancelablePromise<T>\n * @throws ApiError\n */\n public override request<T>(options: ApiRequestOptions): CancelablePromise<T> {\n return __request(this.config, options);\n }\n}\n","/* generated using openapi-typescript-codegen -- do no edit */\n/* istanbul ignore file */\n/* tslint:disable */\n/* eslint-disable */\nimport type { CancelablePromise } from '../core/CancelablePromise';\nimport type { BaseHttpRequest } from '../core/BaseHttpRequest';\nexport class DefaultService {\n constructor(public readonly httpRequest: BaseHttpRequest) {}\n /**\n * @deprecated\n * DEPRECATED: we no longer support prompt caching.\n * @param requestBody\n * @returns any Successful response\n * @throws ApiError\n */\n public checkCache(\n requestBody: {\n /**\n * Unix timestamp in milliseconds\n */\n requestedAt: number;\n /**\n * JSON-encoded request payload\n */\n reqPayload?: any;\n /**\n * Extra tags to attach to the call for filtering. Eg { \"userId\": \"123\", \"prompt_id\": \"populate-title\" }\n */\n tags?: Record<string, string>;\n },\n ): CancelablePromise<{\n /**\n * JSON-encoded response payload\n */\n respPayload?: any;\n }> {\n return this.httpRequest.request({\n method: 'POST',\n url: '/check-cache',\n body: requestBody,\n mediaType: 'application/json',\n });\n }\n /**\n * OpenAI-compatible route for generating inference and optionally logging the request.\n * @param requestBody\n * @returns any Successful response\n * @throws ApiError\n */\n public createChatCompletion(\n requestBody: Record<string, any>,\n ): CancelablePromise<{\n id: string;\n object: 'chat.completion';\n created: number;\n model: string;\n choices: Array<{\n finish_reason: ('length' | 'function_call' | 'tool_calls' | 'stop' | 'content_filter');\n index: number;\n message: {\n reasoning_content?: string | null;\n content?: string | null;\n refusal?: string | null;\n role: 'assistant';\n function_call?: {\n name?: string;\n arguments?: string;\n } | null;\n tool_calls?: Array<{\n id: string;\n function: {\n name: string;\n arguments: string;\n };\n type: 'function';\n }> | null;\n };\n logprobs?: {\n content?: Array<{\n token: string;\n bytes: Array<number> | null;\n logprob: number;\n top_logprobs: Array<{\n token: string;\n bytes: Array<number> | null;\n logprob: number;\n }>;\n }> | null;\n refusal?: Array<{\n token: string;\n bytes: Array<number> | null;\n logprob: number;\n top_logprobs: Array<{\n token: string;\n bytes: Array<number> | null;\n logprob: number;\n }>;\n }> | null;\n } | null;\n content_filter_results?: Record<string, any>;\n criteria_results?: Record<string, ({\n status: 'success';\n score: number;\n explanation?: string;\n errorCode?: number;\n errorMessage?: string;\n } | {\n status: 'error';\n score?: number;\n explanation?: string;\n errorCode: number;\n errorMessage: string;\n })>;\n }>;\n usage?: {\n prompt_tokens: number;\n completion_tokens: number;\n total_tokens: number;\n prompt_cache_hit_tokens?: number;\n prompt_cache_miss_tokens?: number;\n completion_tokens_details?: {\n reasoning_tokens?: number | null;\n audio_tokens?: number | null;\n text_tokens?: number | null;\n accepted_prediction_tokens?: number | null;\n rejected_prediction_tokens?: number | null;\n } | null;\n prompt_tokens_details?: {\n cached_tokens?: number | null;\n audio_tokens?: number | null;\n } | null;\n criteria?: Record<string, {\n /**\n * The total number of tokens used to generate the criterion judgement. Only returned for OpenPipe-trained reward models currently.\n */\n total_tokens: number;\n }>;\n };\n } | null> {\n return this.httpRequest.request({\n method: 'POST',\n url: '/chat/completions',\n body: requestBody,\n mediaType: 'application/json',\n });\n }\n /**\n * Record request logs from OpenAI models\n * @param requestBody\n * @returns any Successful response\n * @throws ApiError\n */\n public report(\n requestBody: {\n /**\n * Unix timestamp in milliseconds\n */\n requestedAt?: number;\n /**\n * Unix timestamp in milliseconds\n */\n receivedAt?: number;\n /**\n * JSON-encoded request payload\n */\n reqPayload?: any;\n /**\n * JSON-encoded response payload\n */\n respPayload?: any;\n /**\n * HTTP status code of response\n */\n statusCode?: number;\n /**\n * User-friendly error message\n */\n errorMessage?: string;\n /**\n * DEPRECATED: use \"reqPayload.metadata\" to attach extra metadata tags to the call for filtering. Eg { \"userId\": \"123\", \"prompt_id\": \"populate-title\" }\n */\n tags?: Record<string, (string | number | boolean | 'null' | null)>;\n },\n ): CancelablePromise<{\n status: ('ok' | 'error');\n }> {\n return this.httpRequest.request({\n method: 'POST',\n url: '/report',\n body: requestBody,\n mediaType: 'application/json',\n });\n }\n /**\n * Record request logs from Anthropic models\n * @param requestBody\n * @returns any Successful response\n * @throws ApiError\n */\n public reportAnthropic(\n requestBody: {\n /**\n * Unix timestamp in milliseconds\n */\n requestedAt?: number;\n /**\n * Unix timestamp in milliseconds\n */\n receivedAt?: number;\n /**\n * JSON-encoded request payload\n */\n reqPayload?: Record<string, any>;\n /**\n * JSON-encoded response payload\n */\n respPayload?: {\n id: string;\n content: Array<({\n text: string;\n type: 'text';\n citations?: Array<({\n cited_text: string;\n document_index: number;\n document_title: string | null;\n end_char_index: number;\n start_char_index: number;\n type: 'char_location';\n } | {\n cited_text: string;\n document_index: number;\n document_title: string | null;\n end_page_number: number;\n start_page_number: number;\n type: 'page_location';\n } | {\n cited_text: string;\n document_index: number;\n document_title: string | null;\n end_block_index: number;\n start_block_index: number;\n type: 'content_block_location';\n })> | null;\n } | {\n id: string;\n name: string;\n type: 'tool_use';\n input?: any;\n } | {\n thinking: string;\n signature: string;\n type: 'thinking';\n } | {\n data: string;\n type: 'redacted_thinking';\n })>;\n model: string;\n role: 'assistant';\n stop_reason: ('end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use' | 'null' | null);\n stop_sequence: (string | 'null' | null);\n type: 'message';\n usage: {\n input_tokens: number;\n output_tokens: number;\n cache_creation_input_tokens: number | null;\n cache_read_input_tokens: number | null;\n };\n };\n /**\n * HTTP status code of response\n */\n statusCode?: number;\n /**\n * User-friendly error message\n */\n errorMessage?: string;\n /**\n * Extra metadata tags to attach to the call for filtering. Eg { \"userId\": \"123\", \"prompt_id\": \"populate-title\" }\n */\n metadata?: Record<string, string>;\n /**\n * Deprecated: use \"metadata\" instead\n */\n tags?: Record<string, (string | number | boolean | 'null' | null)>;\n },\n ): CancelablePromise<{\n status: ('ok' | 'error');\n }> {\n return this.httpRequest.request({\n method: 'POST',\n url: '/report-anthropic',\n body: requestBody,\n mediaType: 'application/json',\n });\n }\n /**\n * @deprecated\n * DEPRECATED: use \"/logs/update-metadata\" instead\n * @param requestBody\n * @returns any Successful response\n * @throws ApiError\n */\n public updateLogTags(\n requestBody: {\n filters: Array<{\n /**\n * The field to filter on. Possible fields include: `model`, `completionId`, and `tags.your_tag_name`.\n */\n field: string;\n equals: (string | number | boolean);\n }>;\n /**\n * Extra tags to attach to the call for filtering. Eg { \"userId\": \"123\", \"prompt_id\": \"populate-title\" }\n */\n tags: Record<string, (string | number | boolean | 'null' | null)>;\n },\n ): CancelablePromise<{\n matchedLogs: number;\n }> {\n return this.httpRequest.request({\n method: 'POST',\n url: '/logs/update-tags',\n body: requestBody,\n mediaType: 'application/json',\n });\n }\n /**\n * Update tags metadata for logged calls matching the provided filters.\n * @param requestBody\n * @returns any Successful response\n * @throws ApiError\n */\n public updateLogMetadata(\n requestBody: {\n filters: Array<{\n /**\n * The field to filter on. Possible fields include: `model`, `completionId`, and `metadata.your_tag_name`.\n */\n field: string;\n equals: (string | number | boolean);\n }>;\n /**\n * Extra metadata to attach to the call for filtering. Eg { \"userId\": \"123\", \"prompt_id\": \"populate-title\" }\n */\n metadata: Record<string, (string | 'null' | null)>;\n },\n ): CancelablePromise<{\n matchedLogs: number;\n }> {\n return this.httpRequest.request({\n method: 'POST',\n url: '/logs/update-metadata',\n body: requestBody,\n mediaType: 'application/json',\n });\n }\n /**\n * Get the latest logged call (only for local testing)\n * @returns any Successful response\n * @throws ApiError\n */\n public localTestingOnlyGetLatestLoggedCall(): CancelablePromise<{\n createdAt: string;\n cacheHit: boolean;\n statusCode: number | null;\n errorMessage: string | null;\n reqPayload?: any;\n respPayload?: any;\n tags: Record<string, string | null>;\n metadata: Record<string, string | null>;\n } | null> {\n return this.httpRequest.request({\n method: 'GET',\n url: '/local-testing-only-get-latest-logged-call',\n });\n }\n /**\n * Get a judgement of a completion against the specified criterion\n * @param requestBody\n * @returns any Successful response\n * @throws ApiError\n */\n public getCriterionJudgement(\n requestBody: {\n /**\n * The ID of the criterion to judge.\n */\n criterion_id: string;\n input?: {\n /**\n * All messages sent to the model when generating the output.\n */\n messages: Array<({\n role: 'system';\n content?: (string | Array<{\n type: 'text';\n text: string;\n }>);\n name?: string;\n } | {\n role: 'user';\n content?: (string | Array<({\n type: 'text';\n text: string;\n } | {\n type: 'image_url';\n image_url: {\n detail?: ('auto' | 'low' | 'high');\n url: string;\n };\n } | {\n type: 'input_audio';\n input_audio: {\n data: string;\n format: 'wav' | 'mp3';\n };\n })>);\n name?: string;\n } | {\n role: 'assistant';\n audio?: {\n id: string;\n } | null;\n content?: (string | Array<({\n type: 'text';\n text: string;\n } | {\n type: 'refusal';\n refusal: string;\n })> | 'null' | null);\n function_call?: {\n name?: string;\n arguments?: string;\n } | null;\n tool_calls?: Array<{\n id: string;\n function: {\n name: string;\n arguments: string;\n };\n type: 'function';\n }> | null;\n name?: string;\n refusal?: string | null;\n annotations?: Array<{\n type: 'url_citation';\n url_citation: {\n start_index: number;\n end_index: number;\n title: string;\n url: string;\n };\n }>;\n } | {\n role: 'developer';\n content?: (string | Array<{\n type: 'text';\n text: string;\n }>);\n name?: string;\n } | {\n role: 'tool';\n content?: (string | Array<{\n type: 'text';\n text: string;\n }>);\n tool_call_id: string;\n } | {\n role: 'function';\n name: string;\n content: (string | 'null' | null);\n })>;\n /**\n * The tool choice to use when generating the output, if any.\n */\n tool_choice?: ('none' | 'auto' | 'required' | {\n type?: 'function';\n function?: {\n name: string;\n };\n });\n /**\n * The tools available to the model when generating the output, if any.\n */\n tools?: Array<{\n function: {\n name: string;\n parameters?: Record<string, any>;\n description?: string;\n strict?: boolean | null;\n };\n type: 'function';\n }>;\n };\n /**\n * The completion message of the model.\n */\n output: {\n reasoning_content?: string | null;\n content?: string | null;\n refusal?: string | null;\n role: 'assistant';\n function_call?: {\n name?: string;\n arguments?: string;\n } | null;\n tool_calls?: Array<{\n id: string;\n function: {\n name: string;\n arguments: string;\n };\n type: 'function';\n }> | null;\n };\n },\n ): CancelablePromise<{\n /**\n * A score of 0 means the output failed this completion, and a score of 1 means it passed. A criteria may also return a decimal scores between 0 and 1, indicating the model's confidence or 'likelihood' that the criteria passed.\n */\n score: number;\n /**\n * An explanation of the score including the model's reasoning, if applicable.\n */\n explanation?: string;\n usage?: {\n /**\n * The total number of tokens used to generate the criterion judgement. Only returned for OpenPipe-trained reward models currently.\n */\n total_tokens: number;\n };\n }> {\n return this.httpRequest.request({\n method: 'POST',\n url: '/criteria/judge',\n body: requestBody,\n mediaType: 'application/json',\n });\n }\n /**\n * Create a new dataset.\n * @param requestBody\n * @returns any Successful response\n * @throws ApiError\n */\n public createDataset(\n requestBody: {\n name: string;\n },\n ): CancelablePromise<{\n object: 'dataset';\n id: string;\n name: string;\n created: string;\n updated: string;\n dataset_entry_count: number;\n fine_tune_count: number;\n }> {\n return this.httpRequest.request({\n method: 'POST',\n url: '/datasets',\n body: requestBody,\n mediaType: 'application/json',\n });\n }\n /**\n * List datasets for a project.\n * @returns any Successful response\n * @throws ApiError\n */\n public listDatasets(): CancelablePromise<{\n object: 'list';\n data: Array<{\n object: 'dataset';\n id: string;\n name: string;\n created: string;\n updated: string;\n dataset_entry_count: number;\n fine_tune_count: number;\n }>;\n }> {\n return this.httpRequest.request({\n method: 'GET',\n url: '/datasets',\n });\n }\n /**\n * Delete a dataset.\n * @param datasetId\n * @returns any Successful response\n * @throws ApiError\n */\n public deleteDataset(\n datasetId: string,\n ): CancelablePromise<{\n id: string;\n object: 'dataset';\n deleted: boolean;\n }> {\n return this.httpRequest.request({\n method: 'DELETE',\n url: '/datasets/{datasetId}',\n path: {\n 'datasetId': datasetId,\n },\n });\n }\n /**\n * Add new dataset entries.\n * @param datasetId\n * @param requestBody\n * @returns any Successful response\n * @throws ApiError\n */\n public createDatasetEntries(\n datasetId: string,\n requestBody: {\n entries: Array<{\n messages: Array<({\n role: 'system';\n content?: (string | Array<{\n type: 'text';\n text: string;\n }>);\n name?: string;\n } | {\n role: 'user';\n content?: (string | Array<({\n type: 'text';\n text: string;\n } | {\n type: 'image_url';\n image_url: {\n detail?: ('auto' | 'low' | 'high');\n url: string;\n };\n } | {\n type: 'input_audio';\n input_audio: {\n data: string;\n format: 'wav' | 'mp3';\n };\n })>);\n name?: string;\n } | {\n role: 'assistant';\n audio?: {\n id: string;\n } | null;\n content?: (string | Array<({\n type: 'text';\n text: string;\n } | {\n type: 'refusal';\n refusal: string;\n })> | 'null' | null);\n function_call?: {\n name?: string;\n arguments?: string;\n } | null;\n tool_calls?: Array<{\n id: string;\n function: {\n name: string;\n arguments: string;\n };\n type: 'function';\n }> | null;\n name?: string;\n refusal?: string | null;\n annotations?: Array<{\n type: 'url_citation';\n url_citation: {\n start_index: number;\n end_index: number;\n title: string;\n url: string;\n };\n }>;\n } | {\n role: 'developer';\n content?: (string | Array<{\n type: 'text';\n text: string;\n }>);\n name?: string;\n } | {\n role: 'tool';\n content?: (string | Array<{\n type: 'text';\n text: string;\n }>);\n tool_call_id: string;\n } | {\n role: 'function';\n name: string;\n content: (string | 'null' | null);\n })>;\n rejected_message?: {\n reasoning_content?: string | null;\n content?: string | null;\n refusal?: string | null;\n role: 'assistant';\n function_call?: {\n name?: string;\n arguments?: string;\n } | null;\n tool_calls?: Array<{\n id: string;\n function: {\n name: string;\n arguments: string;\n };\n type: 'function';\n }> | null;\n };\n tool_choice?: ('none' | 'auto' | 'required' | {\n type?: 'function';\n function?: {\n name: string;\n };\n });\n tools?: Array<{\n function: {\n name: string;\n parameters?: Record<string, any>;\n description?: string;\n strict?: boolean | null;\n };\n type: 'function';\n }>;\n response_format?: ({\n type: 'text';\n } | {\n type: 'json_object';\n } | {\n type: 'json_schema';\n json_schema: {\n name: string;\n description?: string;\n schema?: Record<string, any>;\n strict?: boolean | null;\n };\n });\n split?: 'TRAIN' | 'TEST';\n metadata?: Record<string, string>;\n }>;\n },\n ): CancelablePromise<{\n object: 'dataset.entries.creation';\n entries_created: number;\n errors: {\n object: 'list';\n data: Array<{\n object: 'dataset.entries.creation.error';\n entry_index: number;\n message: string;\n }>;\n };\n }> {\n return this.httpRequest.request({\n method: 'POST',\n url: '/datasets/{datasetId}/entries',\n path: {\n 'datasetId': datasetId,\n },\n body: requestBody,\n mediaType: 'application/json',\n });\n }\n /**\n * Train a new model.\n * @param requestBody\n * @returns any Successful response\n * @throws ApiError\n */\n public createModel(\n requestBody: {\n datasetId: string;\n slug: string;\n pruningRuleIds?: Array<string>;\n trainingConfig: ({\n provider: 'openpipe';\n /**\n * The base model to train from. This could be a base model name or the slug of a previously trained model. Supported base models include: `meta-llama/Meta-Llama-3.1-8B-Instruct`, `meta-llama/Meta-Llama-3.1-70B-Instruct`, `meta-llama/Llama-3.3-70B-Instruct`, `meta-llama/Llama-3.1-8B`, `meta-llama/Llama-3.1-70B`, `Qwen/Qwen2.5-72B-Instruct`, `Qwen/Qwen2.5-Coder-7B-Instruct`, `Qwen/Qwen2.5-Coder-32B-Instruct`, `Qwen/Qwen2.5-1.5B-Instruct`, `Qwen/Qwen2.5-7B-Instruct`, `Qwen/Qwen2-VL-7B-Instruct`, `Qwen/Qwen2.5-14B-Instruct`, `Qwen/Qwen3-8B`, `Qwen/Qwen3-14B`, `mistralai/Mistral-Nemo-Base-2407`, `mistralai/Mistral-Small-24B-Base-2501`, `meta-llama/Llama-3.2-1B-Instruct`, `meta-llama/Llama-3.2-3B-Instruct`, `google/gemma-3-1b-it`, `google/gemma-3-4b-it`, `google/gemma-3-12b-it`, `google/gemma-3-27b-it`\n */\n baseModel: string;\n /**\n * Whether to enable SFT training. If true, the model will be trained using SFT. Can be used in conjunction with DPO training.\n */\n enable_sft?: boolean;\n /**\n * Whether to enable DPO training. If true, the model will be trained using DPO. Can be used in conjunction with SFT training.\n */\n enable_preference_tuning?: boolean;\n /**\n * Hyperparameters for SFT training job. Ensure `enable_sft` is true. If no SFT hyperparameters are provided, default values will be used.\n */\n sft_hyperparameters?: {\n batch_size?: ('auto' | number);\n learning_rate_multiplier?: number;\n num_epochs?: number;\n };\n /**\n * Hyperparameters for DPO training job. Ensure `enable_preference_tuning` is true. If no preference hyperparameters are provided, default values will be used.\n */\n