litellm-api 0.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,55 @@
1
- # LiteLLM API JavaScript SDK
1
+ # litellm-api
2
2
 
3
- Unofficial LiteLLM API JavaScript SDK built from the OpenAPI specification and with TypeScript types.
3
+ Auto-generated, fully typed client for the [LiteLLM proxy API](https://docs.litellm.ai/docs/proxy/quick_start).
4
+
5
+ ## Features
6
+
7
+ - **Fully typed** - every operation, parameter and response is generated from the official OpenAPI spec
8
+ - **Tree-shakable** - only the operations you import end up in your bundle
9
+ - **Runtime agnostic** - uses the global `fetch`, or bring your own implementation
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install litellm-api
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ LiteLLM is self-hosted, so the client requires the `baseUrl` of your proxy:
4
20
 
5
21
  ```ts
6
- const litellm = new LiteLLMApi({ baseUrl, token });
22
+ import { LiteLLMApi } from "litellm-api";
23
+
24
+ const client = new LiteLLMApi({
25
+ baseUrl: "http://localhost:4000",
26
+ token: process.env.LITELLM_MASTER_KEY ?? null,
27
+ });
7
28
 
8
- const assistants = await litellm.request('GET /assistants', {});
29
+ const usage = await client.api.billing.checkUsageBillingUsageGet();
30
+ ```
31
+
32
+ Operations are grouped by tag: `client.api.<tag>.<operation>(params)`.
9
33
 
10
- const models = await litellm.api.modelManagement.modelListModelsGet({ queryParams: { team_id } });
34
+ ### Custom fetch
35
+
36
+ ```ts
37
+ const client = new LiteLLMApi({
38
+ baseUrl: "http://localhost:4000",
39
+ token: process.env.LITELLM_MASTER_KEY ?? null,
40
+ fetch: myFetchImplementation,
41
+ });
11
42
  ```
43
+
44
+ ## Entrypoints
45
+
46
+ | Import | Contents |
47
+ | --- | --- |
48
+ | `litellm-api` | client class, operations, schemas and types |
49
+ | `litellm-api/components` | operations grouped by tag and by path |
50
+ | `litellm-api/schemas` | Zod schemas for every operation |
51
+ | `litellm-api/types` | TypeScript types for every operation |
52
+
53
+ ## License
54
+
55
+ ISC
@@ -0,0 +1,149 @@
1
+ function notEmpty(value) {
2
+ return value !== null && value !== undefined;
3
+ }
4
+ function compactObject(obj) {
5
+ return Object.fromEntries(Object.entries(obj).filter(([, value])=>notEmpty(value)));
6
+ }
7
+
8
+ async function client({ url, method, body, headers, pathParams, queryParams, signal, baseUrl = "", token = null, fetchImpl = fetch }) {
9
+ try {
10
+ const requestHeaders = compactObject({
11
+ "Content-Type": "application/json",
12
+ Authorization: token ? `Bearer ${token}` : undefined,
13
+ ...headers
14
+ });
15
+ if (requestHeaders["Content-Type"]?.toLowerCase().includes("multipart/form-data")) {
16
+ delete requestHeaders["Content-Type"];
17
+ }
18
+ const payload = body instanceof FormData ? body : requestHeaders["Content-Type"] === "application/json" ? JSON.stringify(body) : body;
19
+ const fullUrl = `${baseUrl}${resolveUrl(url, queryParams, pathParams)}`;
20
+ const response = await fetchImpl(fullUrl, {
21
+ signal,
22
+ method: method.toUpperCase(),
23
+ body: payload,
24
+ headers: requestHeaders
25
+ });
26
+ if (!response.ok) {
27
+ let error;
28
+ try {
29
+ error = await response.json();
30
+ } catch (e) {
31
+ error = {
32
+ status: "unknown",
33
+ payload: e instanceof Error ? `Unexpected error (${e.message})` : "Unexpected error"
34
+ };
35
+ }
36
+ throw error;
37
+ }
38
+ if (response.headers?.get("content-type")?.includes("json")) {
39
+ return await response.json();
40
+ } else {
41
+ return await response.text();
42
+ }
43
+ } catch (e) {
44
+ const errorObject = {
45
+ name: "unknown",
46
+ message: e instanceof Error ? `Network error (${e.message})` : "Network error",
47
+ stack: e
48
+ };
49
+ throw errorObject;
50
+ }
51
+ }
52
+ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
53
+ let query = new URLSearchParams(queryParams).toString();
54
+ if (query) query = `?${query}`;
55
+ return url.replace(/\{\w*\}/g, (key)=>pathParams[key.slice(1, -1)] ?? "") + query;
56
+ };
57
+
58
+ /**
59
+ * @summary Create a Stripe Checkout session for API access
60
+ * @description Returns a Stripe Checkout URL. After payment, you'll receive an API key.
61
+ * @link /billing/checkout
62
+ */ async function createCheckoutBillingCheckoutPost({ config } = {}) {
63
+ const { client: request = client, ...requestConfig } = config ?? {};
64
+ const data = await request({
65
+ method: "POST",
66
+ url: `/billing/checkout`,
67
+ ...requestConfig,
68
+ headers: {
69
+ ...requestConfig.headers
70
+ }
71
+ });
72
+ return data;
73
+ }
74
+ /**
75
+ * @summary Check your free-tier usage
76
+ * @description See how many requests you've used today (free tier, by IP).
77
+ * @link /billing/usage
78
+ */ async function checkUsageBillingUsageGet({ config } = {}) {
79
+ const { client: request = client, ...requestConfig } = config ?? {};
80
+ const data = await request({
81
+ method: "GET",
82
+ url: `/billing/usage`,
83
+ ...requestConfig,
84
+ headers: {
85
+ ...requestConfig.headers
86
+ }
87
+ });
88
+ return data;
89
+ }
90
+ /**
91
+ * @summary List the full LiteLLM model catalog
92
+ * @description Returns model pricing, context window sizes, and capability metadata from LiteLLM's built-in catalog. Supports filtering by provider, mode, model name pattern, and pagination.
93
+ * @link /model_catalog
94
+ */ async function listModelCatalogModelCatalogGet({ queryParams, config } = {}) {
95
+ const { client: request = client, ...requestConfig } = config ?? {};
96
+ const data = await request({
97
+ method: "GET",
98
+ url: `/model_catalog`,
99
+ queryParams,
100
+ ...requestConfig,
101
+ headers: {
102
+ ...requestConfig.headers
103
+ }
104
+ });
105
+ return data;
106
+ }
107
+ /**
108
+ * @summary Get a single model from the catalog
109
+ * @description Returns detailed information for a specific model by its exact ID.
110
+ * @link /model_catalog/{model_id}
111
+ */ async function getModelCatalogEntryModelCatalogModelIdGet({ pathParams, config } = {}) {
112
+ const { client: request = client, ...requestConfig } = config ?? {};
113
+ if (!pathParams.model_id) {
114
+ throw new Error(`Missing required path parameter: model_id`);
115
+ }
116
+ const data = await request({
117
+ method: "GET",
118
+ url: `/model_catalog/${pathParams.model_id}`,
119
+ ...requestConfig,
120
+ headers: {
121
+ ...requestConfig.headers
122
+ }
123
+ });
124
+ return data;
125
+ }
126
+ const operationsByPath = {
127
+ "POST /billing/checkout": createCheckoutBillingCheckoutPost,
128
+ "GET /billing/usage": checkUsageBillingUsageGet,
129
+ "GET /model_catalog": listModelCatalogModelCatalogGet,
130
+ "GET /model_catalog/{model_id}": getModelCatalogEntryModelCatalogModelIdGet
131
+ };
132
+ const operationsByTag = {
133
+ billing: {
134
+ createCheckoutBillingCheckoutPost,
135
+ checkUsageBillingUsageGet
136
+ }
137
+ };
138
+ const tagDictionary = {
139
+ billing: {
140
+ POST: [
141
+ "createCheckoutBillingCheckoutPost"
142
+ ],
143
+ GET: [
144
+ "checkUsageBillingUsageGet"
145
+ ]
146
+ }
147
+ };
148
+
149
+ export { operationsByPath as a, checkUsageBillingUsageGet as b, client as c, createCheckoutBillingCheckoutPost as d, getModelCatalogEntryModelCatalogModelIdGet as g, listModelCatalogModelCatalogGet as l, operationsByTag as o, tagDictionary as t };
@@ -0,0 +1,156 @@
1
+ function notEmpty(value) {
2
+ return value !== null && value !== undefined;
3
+ }
4
+ function compactObject(obj) {
5
+ return Object.fromEntries(Object.entries(obj).filter(([, value])=>notEmpty(value)));
6
+ }
7
+
8
+ async function client({ url, method, body, headers, pathParams, queryParams, signal, baseUrl = "", token = null, fetchImpl = fetch }) {
9
+ try {
10
+ const requestHeaders = compactObject({
11
+ "Content-Type": "application/json",
12
+ Authorization: token ? `Bearer ${token}` : undefined,
13
+ ...headers
14
+ });
15
+ if (requestHeaders["Content-Type"]?.toLowerCase().includes("multipart/form-data")) {
16
+ delete requestHeaders["Content-Type"];
17
+ }
18
+ const payload = body instanceof FormData ? body : requestHeaders["Content-Type"] === "application/json" ? JSON.stringify(body) : body;
19
+ const fullUrl = `${baseUrl}${resolveUrl(url, queryParams, pathParams)}`;
20
+ const response = await fetchImpl(fullUrl, {
21
+ signal,
22
+ method: method.toUpperCase(),
23
+ body: payload,
24
+ headers: requestHeaders
25
+ });
26
+ if (!response.ok) {
27
+ let error;
28
+ try {
29
+ error = await response.json();
30
+ } catch (e) {
31
+ error = {
32
+ status: "unknown",
33
+ payload: e instanceof Error ? `Unexpected error (${e.message})` : "Unexpected error"
34
+ };
35
+ }
36
+ throw error;
37
+ }
38
+ if (response.headers?.get("content-type")?.includes("json")) {
39
+ return await response.json();
40
+ } else {
41
+ return await response.text();
42
+ }
43
+ } catch (e) {
44
+ const errorObject = {
45
+ name: "unknown",
46
+ message: e instanceof Error ? `Network error (${e.message})` : "Network error",
47
+ stack: e
48
+ };
49
+ throw errorObject;
50
+ }
51
+ }
52
+ const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
53
+ let query = new URLSearchParams(queryParams).toString();
54
+ if (query) query = `?${query}`;
55
+ return url.replace(/\{\w*\}/g, (key)=>pathParams[key.slice(1, -1)] ?? "") + query;
56
+ };
57
+
58
+ /**
59
+ * @summary Create a Stripe Checkout session for API access
60
+ * @description Returns a Stripe Checkout URL. After payment, you'll receive an API key.
61
+ * @link /billing/checkout
62
+ */ async function createCheckoutBillingCheckoutPost({ config } = {}) {
63
+ const { client: request = client, ...requestConfig } = config ?? {};
64
+ const data = await request({
65
+ method: "POST",
66
+ url: `/billing/checkout`,
67
+ ...requestConfig,
68
+ headers: {
69
+ ...requestConfig.headers
70
+ }
71
+ });
72
+ return data;
73
+ }
74
+ /**
75
+ * @summary Check your free-tier usage
76
+ * @description See how many requests you've used today (free tier, by IP).
77
+ * @link /billing/usage
78
+ */ async function checkUsageBillingUsageGet({ config } = {}) {
79
+ const { client: request = client, ...requestConfig } = config ?? {};
80
+ const data = await request({
81
+ method: "GET",
82
+ url: `/billing/usage`,
83
+ ...requestConfig,
84
+ headers: {
85
+ ...requestConfig.headers
86
+ }
87
+ });
88
+ return data;
89
+ }
90
+ /**
91
+ * @summary List the full LiteLLM model catalog
92
+ * @description Returns model pricing, context window sizes, and capability metadata from LiteLLM's built-in catalog. Supports filtering by provider, mode, model name pattern, and pagination.
93
+ * @link /model_catalog
94
+ */ async function listModelCatalogModelCatalogGet({ queryParams, config } = {}) {
95
+ const { client: request = client, ...requestConfig } = config ?? {};
96
+ const data = await request({
97
+ method: "GET",
98
+ url: `/model_catalog`,
99
+ queryParams,
100
+ ...requestConfig,
101
+ headers: {
102
+ ...requestConfig.headers
103
+ }
104
+ });
105
+ return data;
106
+ }
107
+ /**
108
+ * @summary Get a single model from the catalog
109
+ * @description Returns detailed information for a specific model by its exact ID.
110
+ * @link /model_catalog/{model_id}
111
+ */ async function getModelCatalogEntryModelCatalogModelIdGet({ pathParams, config } = {}) {
112
+ const { client: request = client, ...requestConfig } = config ?? {};
113
+ if (!pathParams.model_id) {
114
+ throw new Error(`Missing required path parameter: model_id`);
115
+ }
116
+ const data = await request({
117
+ method: "GET",
118
+ url: `/model_catalog/${pathParams.model_id}`,
119
+ ...requestConfig,
120
+ headers: {
121
+ ...requestConfig.headers
122
+ }
123
+ });
124
+ return data;
125
+ }
126
+ const operationsByPath = {
127
+ "POST /billing/checkout": createCheckoutBillingCheckoutPost,
128
+ "GET /billing/usage": checkUsageBillingUsageGet,
129
+ "GET /model_catalog": listModelCatalogModelCatalogGet,
130
+ "GET /model_catalog/{model_id}": getModelCatalogEntryModelCatalogModelIdGet
131
+ };
132
+ const operationsByTag = {
133
+ billing: {
134
+ createCheckoutBillingCheckoutPost,
135
+ checkUsageBillingUsageGet
136
+ }
137
+ };
138
+ const tagDictionary = {
139
+ billing: {
140
+ POST: [
141
+ "createCheckoutBillingCheckoutPost"
142
+ ],
143
+ GET: [
144
+ "checkUsageBillingUsageGet"
145
+ ]
146
+ }
147
+ };
148
+
149
+ exports.checkUsageBillingUsageGet = checkUsageBillingUsageGet;
150
+ exports.client = client;
151
+ exports.createCheckoutBillingCheckoutPost = createCheckoutBillingCheckoutPost;
152
+ exports.getModelCatalogEntryModelCatalogModelIdGet = getModelCatalogEntryModelCatalogModelIdGet;
153
+ exports.listModelCatalogModelCatalogGet = listModelCatalogModelCatalogGet;
154
+ exports.operationsByPath = operationsByPath;
155
+ exports.operationsByTag = operationsByTag;
156
+ exports.tagDictionary = tagDictionary;
@@ -0,0 +1,13 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ var components = require('./components-g21ikhwl.cjs');
4
+
5
+
6
+
7
+ exports.checkUsageBillingUsageGet = components.checkUsageBillingUsageGet;
8
+ exports.createCheckoutBillingCheckoutPost = components.createCheckoutBillingCheckoutPost;
9
+ exports.getModelCatalogEntryModelCatalogModelIdGet = components.getModelCatalogEntryModelCatalogModelIdGet;
10
+ exports.listModelCatalogModelCatalogGet = components.listModelCatalogModelCatalogGet;
11
+ exports.operationsByPath = components.operationsByPath;
12
+ exports.operationsByTag = components.operationsByTag;
13
+ exports.tagDictionary = components.tagDictionary;
@@ -0,0 +1,115 @@
1
+ import { FreeTierResponse, CheckoutResponse, GetModelCatalogEntryModelCatalogModelIdGetResponse, ListModelCatalogModelCatalogGetResponse } from './types.mjs';
2
+
3
+ type RequestInit = {
4
+ body?: string | FormData | URLSearchParams | undefined;
5
+ headers?: Record<string, string> | undefined;
6
+ method?: string | undefined;
7
+ signal?: any | undefined;
8
+ };
9
+ type Response = {
10
+ ok: boolean;
11
+ status: number;
12
+ url: string;
13
+ json(): Promise<any>;
14
+ text(): Promise<string>;
15
+ headers?: {
16
+ get(name: string): string | null;
17
+ } | undefined;
18
+ };
19
+ type FetchImpl = (url: string, init?: RequestInit | undefined) => Promise<Response>;
20
+
21
+ type FetcherConfig = {
22
+ baseUrl?: string;
23
+ token?: string | null;
24
+ fetchImpl?: FetchImpl;
25
+ headers?: Record<string, any>;
26
+ };
27
+ type FetcherOptions<TBody, THeaders, TQueryParams, TPathParams> = {
28
+ url: string;
29
+ method: string;
30
+ body?: TBody | undefined;
31
+ headers?: THeaders | undefined;
32
+ queryParams?: TQueryParams | undefined;
33
+ pathParams?: TPathParams | undefined;
34
+ signal?: AbortSignal | undefined;
35
+ } & FetcherConfig;
36
+ declare function client<TData, TError, TBody, THeaders, TQueryParams, TPathParams>({ url, method, body, headers, pathParams, queryParams, signal, baseUrl, token, fetchImpl, }: FetcherOptions<TBody, THeaders, TQueryParams, TPathParams>): Promise<TData>;
37
+
38
+ /**
39
+ * @summary Create a Stripe Checkout session for API access
40
+ * @description Returns a Stripe Checkout URL. After payment, you'll receive an API key.
41
+ * @link /billing/checkout
42
+ */
43
+ declare function createCheckoutBillingCheckoutPost({ config }?: {
44
+ config?: Partial<FetcherConfig> & {
45
+ client?: typeof client;
46
+ };
47
+ }): Promise<CheckoutResponse>;
48
+ /**
49
+ * @summary Check your free-tier usage
50
+ * @description See how many requests you've used today (free tier, by IP).
51
+ * @link /billing/usage
52
+ */
53
+ declare function checkUsageBillingUsageGet({ config }?: {
54
+ config?: Partial<FetcherConfig> & {
55
+ client?: typeof client;
56
+ };
57
+ }): Promise<FreeTierResponse>;
58
+ /**
59
+ * @summary List the full LiteLLM model catalog
60
+ * @description Returns model pricing, context window sizes, and capability metadata from LiteLLM's built-in catalog. Supports filtering by provider, mode, model name pattern, and pagination.
61
+ * @link /model_catalog
62
+ */
63
+ declare function listModelCatalogModelCatalogGet({ queryParams, config, }?: {
64
+ queryParams?: {
65
+ provider?: unknown;
66
+ mode?: unknown;
67
+ model?: unknown;
68
+ supports_vision?: unknown;
69
+ supports_function_calling?: unknown;
70
+ supports_reasoning?: unknown;
71
+ supports_audio_input?: unknown;
72
+ supports_audio_output?: unknown;
73
+ supports_prompt_caching?: unknown;
74
+ supports_response_schema?: unknown;
75
+ page?: number;
76
+ page_size?: number;
77
+ };
78
+ config?: Partial<FetcherConfig> & {
79
+ client?: typeof client;
80
+ };
81
+ }): Promise<ListModelCatalogModelCatalogGetResponse>;
82
+ /**
83
+ * @summary Get a single model from the catalog
84
+ * @description Returns detailed information for a specific model by its exact ID.
85
+ * @link /model_catalog/{model_id}
86
+ */
87
+ declare function getModelCatalogEntryModelCatalogModelIdGet({ pathParams, config, }?: {
88
+ pathParams: {
89
+ model_id: string;
90
+ };
91
+ config?: Partial<FetcherConfig> & {
92
+ client?: typeof client;
93
+ };
94
+ }): Promise<GetModelCatalogEntryModelCatalogModelIdGetResponse>;
95
+ declare const operationsByPath: {
96
+ "POST /billing/checkout": typeof createCheckoutBillingCheckoutPost;
97
+ "GET /billing/usage": typeof checkUsageBillingUsageGet;
98
+ "GET /model_catalog": typeof listModelCatalogModelCatalogGet;
99
+ "GET /model_catalog/{model_id}": typeof getModelCatalogEntryModelCatalogModelIdGet;
100
+ };
101
+ declare const operationsByTag: {
102
+ billing: {
103
+ createCheckoutBillingCheckoutPost: typeof createCheckoutBillingCheckoutPost;
104
+ checkUsageBillingUsageGet: typeof checkUsageBillingUsageGet;
105
+ };
106
+ };
107
+ declare const tagDictionary: {
108
+ readonly billing: {
109
+ readonly POST: readonly ["createCheckoutBillingCheckoutPost"];
110
+ readonly GET: readonly ["checkUsageBillingUsageGet"];
111
+ };
112
+ };
113
+
114
+ export { checkUsageBillingUsageGet, createCheckoutBillingCheckoutPost, getModelCatalogEntryModelCatalogModelIdGet, listModelCatalogModelCatalogGet, operationsByPath, operationsByTag, tagDictionary };
115
+ //# sourceMappingURL=components.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.d.mts","sources":["../src/utils/fetch.ts","../src/utils/fetcher.ts","../src/generated/components.ts"],"mappings":";;AAAA,KAAK,WAAW;AAChB,oBAAoB,QAAQ,GAAG,eAAe;AAC9C,cAAc,MAAM;AACpB;AACA;AACA;AACA,KAAK,QAAQ;AACb;AACA;AACA;AACA,YAAY,OAAO;AACnB,YAAY,OAAO;AACnB;AACA;AACA;AACA;AACA,KAAK,SAAS,wBAAwB,WAAW,iBAAiB,OAAO,CAAC,QAAQ;;ACflF,KAAK,aAAa;AAClB;AACA;AACA,gBAAgB,SAAS;AACzB,cAAc,MAAM;AACpB;AAKA,KAAK,cAAc;AACnB;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,WAAW;AACxB,IAAI,aAAa;AACjB,iBAAiB,MAAM,yJAAyJ,cAAc,+CAA+C,OAAO;;ACZpP;AACA;AACA;AACA;AACA;AACA,iBAAiB,iCAAiC;AAClD,aAAa,OAAO,CAAC,aAAa;AAClC,wBAAwBA,MAAa;AACrC;AACA,IAAI,OAAO,CAACC,gBAAwB;AACpC;AACA;AACA;AACA;AACA;AACA,iBAAiB,yBAAyB;AAC1C,aAAa,OAAO,CAAC,aAAa;AAClC,wBAAwBD,MAAa;AACrC;AACA,IAAI,OAAO,CAACE,gBAAwB;AACpC;AACA;AACA;AACA;AACA;AACA,iBAAiB,+BAA+B;AAChD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,OAAO,CAAC,aAAa;AAClC,wBAAwBF,MAAa;AACrC;AACA,IAAI,OAAO,CAAC,uCAAuC;AACnD;AACA;AACA;AACA;AACA;AACA,iBAAiB,0CAA0C;AAC3D;AACA;AACA;AACA,aAAa,OAAO,CAAC,aAAa;AAClC,wBAAwBA,MAAa;AACrC;AACA,IAAI,OAAO,CAAC,kDAAkD;AAC9D,cAAc,gBAAgB;AAC9B,qCAAqC,iCAAiC;AACtE,iCAAiC,yBAAyB;AAC1D,iCAAiC,+BAA+B;AAChE,4CAA4C,0CAA0C;AACtF;AACA,cAAc,eAAe;AAC7B;AACA,kDAAkD,iCAAiC;AACnF,0CAA0C,yBAAyB;AACnE;AACA;AACA,cAAc,aAAa;AAC3B;AACA;AACA;AACA;AACA;;","names":["defaultClient","__types.CheckoutResponse","__types.FreeTierResponse"]}
@@ -0,0 +1 @@
1
+ export { b as checkUsageBillingUsageGet, d as createCheckoutBillingCheckoutPost, g as getModelCatalogEntryModelCatalogModelIdGet, l as listModelCatalogModelCatalogGet, a as operationsByPath, o as operationsByTag, t as tagDictionary } from './components-e9x5e8kj.js';