litellm-api 1.0.0 → 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 ADDED
@@ -0,0 +1,55 @@
1
+ # litellm-api
2
+
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:
20
+
21
+ ```ts
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
+ });
28
+
29
+ const usage = await client.api.billing.checkUsageBillingUsageGet();
30
+ ```
31
+
32
+ Operations are grouped by tag: `client.api.<tag>.<operation>(params)`.
33
+
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
+ });
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;
@@ -1,157 +1,13 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
 
3
- function notEmpty(value) {
4
- return value !== null && value !== undefined;
5
- }
6
- function compactObject(obj) {
7
- return Object.fromEntries(Object.entries(obj).filter(([, value])=>notEmpty(value)));
8
- }
3
+ var components = require('./components-g21ikhwl.cjs');
9
4
 
10
- async function client({ url, method, body, headers, pathParams, queryParams, signal, baseUrl = "", token = null, fetchImpl = fetch }) {
11
- try {
12
- const requestHeaders = compactObject({
13
- "Content-Type": "application/json",
14
- Authorization: token ? `Bearer ${token}` : undefined,
15
- ...headers
16
- });
17
- if (requestHeaders["Content-Type"]?.toLowerCase().includes("multipart/form-data")) {
18
- delete requestHeaders["Content-Type"];
19
- }
20
- const payload = body instanceof FormData ? body : requestHeaders["Content-Type"] === "application/json" ? JSON.stringify(body) : body;
21
- const fullUrl = `${baseUrl}${resolveUrl(url, queryParams, pathParams)}`;
22
- const response = await fetchImpl(fullUrl, {
23
- signal,
24
- method: method.toUpperCase(),
25
- body: payload,
26
- headers: requestHeaders
27
- });
28
- if (!response.ok) {
29
- let error;
30
- try {
31
- error = await response.json();
32
- } catch (e) {
33
- error = {
34
- status: "unknown",
35
- payload: e instanceof Error ? `Unexpected error (${e.message})` : "Unexpected error"
36
- };
37
- }
38
- throw error;
39
- }
40
- if (response.headers?.get("content-type")?.includes("json")) {
41
- return await response.json();
42
- } else {
43
- return await response.text();
44
- }
45
- } catch (e) {
46
- const errorObject = {
47
- name: "unknown",
48
- message: e instanceof Error ? `Network error (${e.message})` : "Network error",
49
- stack: e
50
- };
51
- throw errorObject;
52
- }
53
- }
54
- const resolveUrl = (url, queryParams = {}, pathParams = {})=>{
55
- let query = new URLSearchParams(queryParams).toString();
56
- if (query) query = `?${query}`;
57
- return url.replace(/\{\w*\}/g, (key)=>pathParams[key.slice(1, -1)] ?? "") + query;
58
- };
59
5
 
60
- /**
61
- * @summary Create a Stripe Checkout session for API access
62
- * @description Returns a Stripe Checkout URL. After payment, you'll receive an API key.
63
- * @link /billing/checkout
64
- */ async function createCheckoutBillingCheckoutPost({ config } = {}) {
65
- const { client: request = client, ...requestConfig } = config ?? {};
66
- const data = await request({
67
- method: "POST",
68
- url: `/billing/checkout`,
69
- ...requestConfig,
70
- headers: {
71
- ...requestConfig.headers
72
- }
73
- });
74
- return data;
75
- }
76
- /**
77
- * @summary Check your free-tier usage
78
- * @description See how many requests you've used today (free tier, by IP).
79
- * @link /billing/usage
80
- */ async function checkUsageBillingUsageGet({ config } = {}) {
81
- const { client: request = client, ...requestConfig } = config ?? {};
82
- const data = await request({
83
- method: "GET",
84
- url: `/billing/usage`,
85
- ...requestConfig,
86
- headers: {
87
- ...requestConfig.headers
88
- }
89
- });
90
- return data;
91
- }
92
- /**
93
- * @summary List the full LiteLLM model catalog
94
- * @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.
95
- * @link /model_catalog
96
- */ async function listModelCatalogModelCatalogGet({ queryParams, config } = {}) {
97
- const { client: request = client, ...requestConfig } = config ?? {};
98
- const data = await request({
99
- method: "GET",
100
- url: `/model_catalog`,
101
- queryParams,
102
- ...requestConfig,
103
- headers: {
104
- ...requestConfig.headers
105
- }
106
- });
107
- return data;
108
- }
109
- /**
110
- * @summary Get a single model from the catalog
111
- * @description Returns detailed information for a specific model by its exact ID.
112
- * @link /model_catalog/{model_id}
113
- */ async function getModelCatalogEntryModelCatalogModelIdGet({ pathParams, config } = {}) {
114
- const { client: request = client, ...requestConfig } = config ?? {};
115
- if (!pathParams.model_id) {
116
- throw new Error(`Missing required path parameter: model_id`);
117
- }
118
- const data = await request({
119
- method: "GET",
120
- url: `/model_catalog/${pathParams.model_id}`,
121
- ...requestConfig,
122
- headers: {
123
- ...requestConfig.headers
124
- }
125
- });
126
- return data;
127
- }
128
- const operationsByPath = {
129
- "POST /billing/checkout": createCheckoutBillingCheckoutPost,
130
- "GET /billing/usage": checkUsageBillingUsageGet,
131
- "GET /model_catalog": listModelCatalogModelCatalogGet,
132
- "GET /model_catalog/{model_id}": getModelCatalogEntryModelCatalogModelIdGet
133
- };
134
- const operationsByTag = {
135
- "billing": {
136
- createCheckoutBillingCheckoutPost,
137
- checkUsageBillingUsageGet
138
- }
139
- };
140
- const tagDictionary = {
141
- "billing": {
142
- "POST": [
143
- "createCheckoutBillingCheckoutPost"
144
- ],
145
- "GET": [
146
- "checkUsageBillingUsageGet"
147
- ]
148
- }
149
- };
150
6
 
151
- exports.checkUsageBillingUsageGet = checkUsageBillingUsageGet;
152
- exports.createCheckoutBillingCheckoutPost = createCheckoutBillingCheckoutPost;
153
- exports.getModelCatalogEntryModelCatalogModelIdGet = getModelCatalogEntryModelCatalogModelIdGet;
154
- exports.listModelCatalogModelCatalogGet = listModelCatalogModelCatalogGet;
155
- exports.operationsByPath = operationsByPath;
156
- exports.operationsByTag = operationsByTag;
157
- exports.tagDictionary = tagDictionary;
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;