| |
|
|
| import { type Client, http } from '../core.js' |
| import { type Result, type RequestOptions } from '../lib/types.js' |
| import { request } from '../lib/request.js' |
| import { toURLSearchParams, encodeSort } from '../lib/encodings.js' |
| import { |
| toWire, |
| toPathWire, |
| fromWire, |
| assertValid, |
| toSnakeCase, |
| } from '../lib/wire.js' |
| import * as schemas from '../models/schemas.js' |
| import type { |
| ListLlmCostPricesRequest, |
| ListLlmCostPricesResponse, |
| GetLlmCostPriceRequest, |
| GetLlmCostPriceResponse, |
| ListLlmCostOverridesRequest, |
| ListLlmCostOverridesResponse, |
| CreateLlmCostOverrideRequest, |
| CreateLlmCostOverrideResponse, |
| DeleteLlmCostOverrideRequest, |
| DeleteLlmCostOverrideResponse, |
| } from '../models/operations/llmCost.js' |
|
|
| |
| |
| |
| |
| |
| |
| |
| export function listLlmCostPrices( |
| client: Client, |
| req: ListLlmCostPricesRequest = {}, |
| options?: RequestOptions, |
| ): Promise<Result<ListLlmCostPricesResponse>> { |
| return request(() => { |
| if (client._options.validate && req.sort !== undefined) { |
| assertValid(schemas.listLlmCostPricesQueryParams.shape.sort, req.sort) |
| } |
| const query = toWire( |
| { |
| filter: req.filter, |
| sort: encodeSort(req.sort, toSnakeCase), |
| page: req.page, |
| }, |
| schemas.listLlmCostPricesQueryParams, |
| ) |
| if (client._options.validate) { |
| assertValid(schemas.listLlmCostPricesQueryParamsWire, query) |
| } |
| const searchParams = toURLSearchParams(query) |
| return http(client) |
| .get('openmeter/llm-cost/prices', { ...options, searchParams }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.listLlmCostPricesResponseWire, data) |
| } |
| return fromWire(data, schemas.listLlmCostPricesResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| export function getLlmCostPrice( |
| client: Client, |
| req: GetLlmCostPriceRequest, |
| options?: RequestOptions, |
| ): Promise<Result<GetLlmCostPriceResponse>> { |
| return request(() => { |
| const pathParamsInput = { |
| priceId: req.priceId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.getLlmCostPricePathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.getLlmCostPricePathParamsWire, pathParams) |
| } |
| const path = `openmeter/llm-cost/prices/${(() => { |
| if (pathParams.priceId === undefined) { |
| throw new Error('missing path parameter: priceId') |
| } |
| return encodeURIComponent(String(pathParams.priceId)) |
| })()}` |
| return http(client) |
| .get(path, options) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.getLlmCostPriceResponseWire, data) |
| } |
| return fromWire(data, schemas.getLlmCostPriceResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| export function listLlmCostOverrides( |
| client: Client, |
| req: ListLlmCostOverridesRequest = {}, |
| options?: RequestOptions, |
| ): Promise<Result<ListLlmCostOverridesResponse>> { |
| return request(() => { |
| const query = toWire( |
| { |
| filter: req.filter, |
| page: req.page, |
| }, |
| schemas.listLlmCostOverridesQueryParams, |
| ) |
| if (client._options.validate) { |
| assertValid(schemas.listLlmCostOverridesQueryParamsWire, query) |
| } |
| const searchParams = toURLSearchParams(query) |
| return http(client) |
| .get('openmeter/llm-cost/overrides', { ...options, searchParams }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.listLlmCostOverridesResponseWire, data) |
| } |
| return fromWire(data, schemas.listLlmCostOverridesResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| export function createLlmCostOverride( |
| client: Client, |
| req: CreateLlmCostOverrideRequest, |
| options?: RequestOptions, |
| ): Promise<Result<CreateLlmCostOverrideResponse>> { |
| return request(() => { |
| const body = toWire(req, schemas.createLlmCostOverrideBody) |
| if (client._options.validate) { |
| assertValid(schemas.createLlmCostOverrideBodyWire, body) |
| } |
| return http(client) |
| .post('openmeter/llm-cost/overrides', { ...options, json: body }) |
| .json() |
| .then((data) => { |
| if (client._options.validate) { |
| assertValid(schemas.createLlmCostOverrideResponseWire, data) |
| } |
| return fromWire(data, schemas.createLlmCostOverrideResponse) |
| }) |
| }) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| export function deleteLlmCostOverride( |
| client: Client, |
| req: DeleteLlmCostOverrideRequest, |
| options?: RequestOptions, |
| ): Promise<Result<DeleteLlmCostOverrideResponse>> { |
| return request(async () => { |
| const pathParamsInput = { |
| priceId: req.priceId, |
| } |
| const pathParams = client._options.validate |
| ? toPathWire(pathParamsInput, schemas.deleteLlmCostOverridePathParams) |
| : pathParamsInput |
| if (client._options.validate) { |
| assertValid(schemas.deleteLlmCostOverridePathParamsWire, pathParams) |
| } |
| const path = `openmeter/llm-cost/overrides/${(() => { |
| if (pathParams.priceId === undefined) { |
| throw new Error('missing path parameter: priceId') |
| } |
| return encodeURIComponent(String(pathParams.priceId)) |
| })()}` |
| await http(client).delete(path, options) |
| }) |
| } |
|
|