File size: 5,925 Bytes
1477a90 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
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'
/**
* List LLM cost prices
*
* List global LLM cost prices. Returns prices with overrides applied if any.
*
* GET /openmeter/llm-cost/prices
*/
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)
})
})
}
/**
* Get LLM cost price
*
* Get a specific LLM cost price by ID. Returns the price with overrides applied if
* any.
*
* GET /openmeter/llm-cost/prices/{priceId}
*/
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)
})
})
}
/**
* List LLM cost overrides
*
* List per-namespace price overrides.
*
* GET /openmeter/llm-cost/overrides
*/
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)
})
})
}
/**
* Create LLM cost override
*
* Create a per-namespace price override.
*
* POST /openmeter/llm-cost/overrides
*/
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)
})
})
}
/**
* Delete LLM cost override
*
* Delete a per-namespace price override.
*
* DELETE /openmeter/llm-cost/overrides/{priceId}
*/
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)
})
}
|