liter_llm 1.0.0.pre.rc.6

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.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +239 -0
  3. data/ext/liter_llm_rb/extconf.rb +65 -0
  4. data/ext/liter_llm_rb/native/.cargo/config.toml +23 -0
  5. data/ext/liter_llm_rb/native/Cargo.lock +3713 -0
  6. data/ext/liter_llm_rb/native/Cargo.toml +32 -0
  7. data/ext/liter_llm_rb/native/build.rs +15 -0
  8. data/ext/liter_llm_rb/native/src/lib.rs +1079 -0
  9. data/lib/liter_llm.rb +8 -0
  10. data/sig/liter_llm.rbs +416 -0
  11. data/vendor/Cargo.toml +54 -0
  12. data/vendor/liter-llm/Cargo.toml +92 -0
  13. data/vendor/liter-llm/README.md +252 -0
  14. data/vendor/liter-llm/schemas/pricing.json +40 -0
  15. data/vendor/liter-llm/schemas/providers.json +1662 -0
  16. data/vendor/liter-llm/src/auth/azure_ad.rs +264 -0
  17. data/vendor/liter-llm/src/auth/bedrock_sts.rs +353 -0
  18. data/vendor/liter-llm/src/auth/mod.rs +68 -0
  19. data/vendor/liter-llm/src/auth/vertex_oauth.rs +353 -0
  20. data/vendor/liter-llm/src/client/config.rs +351 -0
  21. data/vendor/liter-llm/src/client/managed.rs +622 -0
  22. data/vendor/liter-llm/src/client/mod.rs +864 -0
  23. data/vendor/liter-llm/src/cost.rs +212 -0
  24. data/vendor/liter-llm/src/error.rs +190 -0
  25. data/vendor/liter-llm/src/http/eventstream.rs +860 -0
  26. data/vendor/liter-llm/src/http/mod.rs +12 -0
  27. data/vendor/liter-llm/src/http/request.rs +438 -0
  28. data/vendor/liter-llm/src/http/retry.rs +72 -0
  29. data/vendor/liter-llm/src/http/streaming.rs +289 -0
  30. data/vendor/liter-llm/src/lib.rs +37 -0
  31. data/vendor/liter-llm/src/provider/anthropic.rs +2250 -0
  32. data/vendor/liter-llm/src/provider/azure.rs +579 -0
  33. data/vendor/liter-llm/src/provider/bedrock.rs +1543 -0
  34. data/vendor/liter-llm/src/provider/cohere.rs +654 -0
  35. data/vendor/liter-llm/src/provider/custom.rs +404 -0
  36. data/vendor/liter-llm/src/provider/google_ai.rs +281 -0
  37. data/vendor/liter-llm/src/provider/mistral.rs +188 -0
  38. data/vendor/liter-llm/src/provider/mod.rs +616 -0
  39. data/vendor/liter-llm/src/provider/vertex.rs +1504 -0
  40. data/vendor/liter-llm/src/tests.rs +1425 -0
  41. data/vendor/liter-llm/src/tokenizer.rs +281 -0
  42. data/vendor/liter-llm/src/tower/budget.rs +599 -0
  43. data/vendor/liter-llm/src/tower/cache.rs +502 -0
  44. data/vendor/liter-llm/src/tower/cache_opendal.rs +270 -0
  45. data/vendor/liter-llm/src/tower/cooldown.rs +231 -0
  46. data/vendor/liter-llm/src/tower/cost.rs +404 -0
  47. data/vendor/liter-llm/src/tower/fallback.rs +121 -0
  48. data/vendor/liter-llm/src/tower/health.rs +219 -0
  49. data/vendor/liter-llm/src/tower/hooks.rs +369 -0
  50. data/vendor/liter-llm/src/tower/mod.rs +77 -0
  51. data/vendor/liter-llm/src/tower/rate_limit.rs +300 -0
  52. data/vendor/liter-llm/src/tower/router.rs +436 -0
  53. data/vendor/liter-llm/src/tower/service.rs +181 -0
  54. data/vendor/liter-llm/src/tower/tests.rs +539 -0
  55. data/vendor/liter-llm/src/tower/tests_common.rs +252 -0
  56. data/vendor/liter-llm/src/tower/tracing.rs +209 -0
  57. data/vendor/liter-llm/src/tower/types.rs +170 -0
  58. data/vendor/liter-llm/src/types/audio.rs +52 -0
  59. data/vendor/liter-llm/src/types/batch.rs +77 -0
  60. data/vendor/liter-llm/src/types/chat.rs +214 -0
  61. data/vendor/liter-llm/src/types/common.rs +244 -0
  62. data/vendor/liter-llm/src/types/embedding.rs +84 -0
  63. data/vendor/liter-llm/src/types/files.rs +58 -0
  64. data/vendor/liter-llm/src/types/image.rs +40 -0
  65. data/vendor/liter-llm/src/types/mod.rs +27 -0
  66. data/vendor/liter-llm/src/types/models.rs +21 -0
  67. data/vendor/liter-llm/src/types/moderation.rs +80 -0
  68. data/vendor/liter-llm/src/types/ocr.rs +87 -0
  69. data/vendor/liter-llm/src/types/rerank.rs +46 -0
  70. data/vendor/liter-llm/src/types/responses.rs +55 -0
  71. data/vendor/liter-llm/src/types/search.rs +45 -0
  72. data/vendor/liter-llm/tests/contract.rs +332 -0
  73. data/vendor/liter-llm-ffi/Cargo.toml +30 -0
  74. data/vendor/liter-llm-ffi/build.rs +66 -0
  75. data/vendor/liter-llm-ffi/cbindgen.toml +60 -0
  76. data/vendor/liter-llm-ffi/liter_llm.h +850 -0
  77. data/vendor/liter-llm-ffi/src/lib.rs +2488 -0
  78. metadata +286 -0
@@ -0,0 +1,850 @@
1
+ /* Auto-generated C bindings for liter-llm */
2
+
3
+ #ifndef LITER_LLM_FFI_H
4
+ #define LITER_LLM_FFI_H
5
+
6
+ #pragma once
7
+
8
+ /* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */
9
+
10
+ #define LITER_LLM_VERSION_MAJOR 1
11
+ #define LITER_LLM_VERSION_MINOR 0
12
+ #define LITER_LLM_VERSION_PATCH 0
13
+ #define LITER_LLM_VERSION "1.0.0-rc.6"
14
+
15
+
16
+ #include <stdarg.h>
17
+ #include <stdbool.h>
18
+ #include <stdint.h>
19
+ #include <stdlib.h>
20
+ /* Symbol visibility */
21
+ #ifndef LITER_LLM_EXPORT
22
+ #if defined(LITER_LLM_STATIC)
23
+ #define LITER_LLM_EXPORT
24
+ #elif defined(_WIN32) || defined(__CYGWIN__)
25
+ #ifdef LITER_LLM_BUILDING
26
+ #define LITER_LLM_EXPORT __declspec(dllexport)
27
+ #else
28
+ #define LITER_LLM_EXPORT __declspec(dllimport)
29
+ #endif
30
+ #elif defined(__GNUC__) || defined(__clang__)
31
+ #define LITER_LLM_EXPORT __attribute__((visibility("default")))
32
+ #else
33
+ #define LITER_LLM_EXPORT
34
+ #endif
35
+ #endif
36
+
37
+ /* Compiler attribute helpers
38
+ *
39
+ * LITER_LLM_WARN_UNUSED — caller must not discard the return value (e.g. an
40
+ * allocated pointer or an error code).
41
+ * LITER_LLM_NONNULL(...) — the listed 1-based argument positions must never be
42
+ * NULL. Callers that pass NULL trigger UB; annotating
43
+ * this lets GCC/Clang warn at compile time.
44
+ */
45
+ #if defined(__GNUC__) || defined(__clang__)
46
+ # define LITER_LLM_WARN_UNUSED __attribute__((warn_unused_result))
47
+ # define LITER_LLM_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
48
+ #else
49
+ # define LITER_LLM_WARN_UNUSED
50
+ # define LITER_LLM_NONNULL(...)
51
+ #endif
52
+
53
+ /**
54
+ * Opaque handle to a liter-llm client.
55
+ * Create with literllm_client_new(), free with literllm_client_free().
56
+ */
57
+ typedef struct LiterLlmClient LiterLlmClient;
58
+
59
+
60
+ /**
61
+ * Callback invoked for each SSE chunk during a streaming chat completion.
62
+ *
63
+ * - `chunk_json`: NUL-terminated JSON string for one `ChatCompletionChunk`.
64
+ * The pointer is valid only for the duration of the callback invocation.
65
+ * The callee must **not** free it.
66
+ * - `user_data`: The opaque pointer passed to [`literllm_chat_stream`].
67
+ *
68
+ * This callback returns void; there is no return value.
69
+ */
70
+ typedef void (*LiterLlmStreamCallback)(const char *chunk_json, void *user_data);
71
+
72
+ /**
73
+ * Function pointer struct for lifecycle hook callbacks.
74
+ *
75
+ * All function pointers are optional (may be NULL). When non-NULL, the
76
+ * corresponding callback is invoked at the appropriate lifecycle point.
77
+ *
78
+ * # Memory ownership
79
+ *
80
+ * - `request_json` passed to callbacks is a NUL-terminated JSON string owned
81
+ * by the caller (liter-llm). The hook must **not** free it; it is valid
82
+ * only for the duration of the callback invocation.
83
+ * - `response_json` and `error_message` follow the same ownership rules.
84
+ * - `user_data` is forwarded as-is to each callback; the caller is
85
+ * responsible for its lifetime and thread safety.
86
+ */
87
+ typedef struct LiterLlmHookCallbacks {
88
+ /**
89
+ * Called before the request is sent.
90
+ *
91
+ * Return `0` to proceed, or non-zero to reject the request (guardrail).
92
+ * When non-zero is returned, `literllm_last_error` will contain the
93
+ * rejection message if set by the hook.
94
+ */
95
+ int32_t (*on_request)(const char *request_json, void *user_data);
96
+ /**
97
+ * Called after a successful response.
98
+ */
99
+ void (*on_response)(const char *request_json, const char *response_json, void *user_data);
100
+ /**
101
+ * Called when the request fails with an error.
102
+ */
103
+ void (*on_error)(const char *request_json, const char *error_message, void *user_data);
104
+ /**
105
+ * Opaque user data pointer forwarded to all callbacks.
106
+ */
107
+ void *user_data;
108
+ } LiterLlmHookCallbacks;
109
+
110
+ /**
111
+ * Create a new liter-llm client.
112
+ *
113
+ * # Parameters
114
+ *
115
+ * - `api_key`: NUL-terminated API key string. Pass an empty string (`""`)
116
+ * when using a provider that does not require authentication.
117
+ * - `base_url`: NUL-terminated base URL override. Pass `NULL` to use the
118
+ * default provider routing based on model-name prefix.
119
+ * - `model_hint`: NUL-terminated model name hint for provider auto-detection
120
+ * (e.g. `"groq/llama3-70b"`). Pass `NULL` to default to OpenAI. Used
121
+ * only when `base_url` is also `NULL`.
122
+ *
123
+ * # Return value
124
+ *
125
+ * Returns a heap-allocated `LiterLlmClient*` on success, or `NULL` on failure.
126
+ * Check [`literllm_last_error`] for the error message when `NULL` is returned.
127
+ *
128
+ * The returned pointer must be freed with [`literllm_client_free`].
129
+ *
130
+ * # Safety
131
+ *
132
+ * - `api_key` must be a valid, non-null, NUL-terminated C string.
133
+ * - `base_url` may be `NULL` (treated as no override) or a valid NUL-terminated C string.
134
+ * - `model_hint` may be `NULL` (treated as no hint) or a valid NUL-terminated C string.
135
+ * - The caller owns the returned pointer and must call `literllm_client_free` exactly once.
136
+ */
137
+ LITER_LLM_EXPORT
138
+ LiterLlmClient *literllm_client_new(const char *api_key,
139
+ const char *base_url,
140
+ const char *model_hint);
141
+
142
+ /**
143
+ * Free a client created by [`literllm_client_new`].
144
+ *
145
+ * # Safety
146
+ *
147
+ * - `client` must be a valid pointer returned by `literllm_client_new`.
148
+ * - `client` must not be used after this call (use-after-free is UB).
149
+ * - Passing `NULL` is safe and is a no-op.
150
+ */
151
+ LITER_LLM_EXPORT void literllm_client_free(LiterLlmClient *client);
152
+
153
+ /**
154
+ * Send a chat completion request.
155
+ *
156
+ * # Parameters
157
+ *
158
+ * - `client`: A valid client pointer.
159
+ * - `request_json`: NUL-terminated JSON string conforming to the
160
+ * `ChatCompletionRequest` schema.
161
+ *
162
+ * # Return value
163
+ *
164
+ * Returns a heap-allocated NUL-terminated JSON string containing the
165
+ * `ChatCompletionResponse` on success, or `NULL` on failure.
166
+ * Check [`literllm_last_error`] on failure.
167
+ *
168
+ * The caller must free the returned string with [`literllm_free_string`].
169
+ *
170
+ * # Safety
171
+ *
172
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
173
+ * - `request_json` must be a valid, non-null, NUL-terminated UTF-8 JSON string.
174
+ */
175
+ LITER_LLM_EXPORT char *literllm_chat(const LiterLlmClient *client, const char *request_json);
176
+
177
+ /**
178
+ * Send a streaming chat completion request, invoking a callback for each chunk.
179
+ *
180
+ * # Parameters
181
+ *
182
+ * - `client`: A valid client pointer.
183
+ * - `request_json`: NUL-terminated JSON string conforming to the
184
+ * `ChatCompletionRequest` schema.
185
+ * - `callback`: Function called once per SSE chunk with the JSON-serialised
186
+ * `ChatCompletionChunk`. The `chunk_json` pointer is valid only for the
187
+ * duration of each callback invocation and must **not** be freed.
188
+ * - `user_data`: Opaque pointer forwarded unchanged to each `callback` call.
189
+ * May be `NULL`.
190
+ *
191
+ * # Return value
192
+ *
193
+ * Returns `0` on success (all chunks delivered) or `-1` on failure.
194
+ * Check [`literllm_last_error`] on failure.
195
+ *
196
+ * # Safety
197
+ *
198
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
199
+ * - `request_json` must be a valid, non-null, NUL-terminated UTF-8 JSON string.
200
+ * - `callback` must be a valid function pointer; it is invoked from the calling
201
+ * thread with the Tokio runtime blocked.
202
+ * - `user_data` is forwarded as-is; the caller is responsible for its lifetime.
203
+ */
204
+ LITER_LLM_EXPORT
205
+ int32_t literllm_chat_stream(const LiterLlmClient *client,
206
+ const char *request_json,
207
+ LiterLlmStreamCallback callback,
208
+ void *user_data);
209
+
210
+ /**
211
+ * Send an embedding request.
212
+ *
213
+ * # Parameters
214
+ *
215
+ * - `client`: A valid client pointer.
216
+ * - `request_json`: NUL-terminated JSON string conforming to the
217
+ * `EmbeddingRequest` schema.
218
+ *
219
+ * # Return value
220
+ *
221
+ * Returns a heap-allocated NUL-terminated JSON string containing the
222
+ * `EmbeddingResponse` on success, or `NULL` on failure.
223
+ * Check [`literllm_last_error`] on failure.
224
+ *
225
+ * The caller must free the returned string with [`literllm_free_string`].
226
+ *
227
+ * # Safety
228
+ *
229
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
230
+ * - `request_json` must be a valid, non-null, NUL-terminated UTF-8 JSON string.
231
+ */
232
+ LITER_LLM_EXPORT char *literllm_embed(const LiterLlmClient *client, const char *request_json);
233
+
234
+ /**
235
+ * List available models.
236
+ *
237
+ * # Parameters
238
+ *
239
+ * - `client`: A valid client pointer.
240
+ *
241
+ * # Return value
242
+ *
243
+ * Returns a heap-allocated NUL-terminated JSON string containing the
244
+ * `ModelsListResponse` on success, or `NULL` on failure.
245
+ * Check [`literllm_last_error`] on failure.
246
+ *
247
+ * The caller must free the returned string with [`literllm_free_string`].
248
+ *
249
+ * # Safety
250
+ *
251
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
252
+ */
253
+ LITER_LLM_EXPORT char *literllm_list_models(const LiterLlmClient *client);
254
+
255
+ /**
256
+ * Generate an image from a text prompt.
257
+ *
258
+ * # Parameters
259
+ *
260
+ * - `client`: A valid client pointer.
261
+ * - `request_json`: NUL-terminated JSON string conforming to the
262
+ * `CreateImageRequest` schema.
263
+ *
264
+ * # Return value
265
+ *
266
+ * Returns a heap-allocated NUL-terminated JSON string containing the
267
+ * `ImagesResponse` on success, or `NULL` on failure.
268
+ * The caller must free the returned string with [`literllm_free_string`].
269
+ *
270
+ * # Safety
271
+ *
272
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
273
+ * - `request_json` must be a valid, non-null, NUL-terminated UTF-8 JSON string.
274
+ */
275
+ LITER_LLM_EXPORT
276
+ char *literllm_image_generate(const LiterLlmClient *client,
277
+ const char *request_json);
278
+
279
+ /**
280
+ * Generate speech audio from text.
281
+ *
282
+ * # Parameters
283
+ *
284
+ * - `client`: A valid client pointer.
285
+ * - `request_json`: NUL-terminated JSON string conforming to the
286
+ * `CreateSpeechRequest` schema.
287
+ *
288
+ * # Return value
289
+ *
290
+ * Returns a heap-allocated NUL-terminated base64-encoded string of the audio
291
+ * bytes on success, or `NULL` on failure.
292
+ * The caller must free the returned string with [`literllm_free_string`].
293
+ *
294
+ * # Safety
295
+ *
296
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
297
+ * - `request_json` must be a valid, non-null, NUL-terminated UTF-8 JSON string.
298
+ */
299
+ LITER_LLM_EXPORT char *literllm_speech(const LiterLlmClient *client, const char *request_json);
300
+
301
+ /**
302
+ * Transcribe audio to text.
303
+ *
304
+ * # Parameters
305
+ *
306
+ * - `client`: A valid client pointer.
307
+ * - `request_json`: NUL-terminated JSON string conforming to the
308
+ * `CreateTranscriptionRequest` schema.
309
+ *
310
+ * # Return value
311
+ *
312
+ * Returns a heap-allocated NUL-terminated JSON string containing the
313
+ * `TranscriptionResponse` on success, or `NULL` on failure.
314
+ * The caller must free the returned string with [`literllm_free_string`].
315
+ *
316
+ * # Safety
317
+ *
318
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
319
+ * - `request_json` must be a valid, non-null, NUL-terminated UTF-8 JSON string.
320
+ */
321
+ LITER_LLM_EXPORT char *literllm_transcribe(const LiterLlmClient *client, const char *request_json);
322
+
323
+ /**
324
+ * Check content against moderation policies.
325
+ *
326
+ * # Parameters
327
+ *
328
+ * - `client`: A valid client pointer.
329
+ * - `request_json`: NUL-terminated JSON string conforming to the
330
+ * `ModerationRequest` schema.
331
+ *
332
+ * # Return value
333
+ *
334
+ * Returns a heap-allocated NUL-terminated JSON string containing the
335
+ * `ModerationResponse` on success, or `NULL` on failure.
336
+ * The caller must free the returned string with [`literllm_free_string`].
337
+ *
338
+ * # Safety
339
+ *
340
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
341
+ * - `request_json` must be a valid, non-null, NUL-terminated UTF-8 JSON string.
342
+ */
343
+ LITER_LLM_EXPORT char *literllm_moderate(const LiterLlmClient *client, const char *request_json);
344
+
345
+ /**
346
+ * Rerank documents by relevance to a query.
347
+ *
348
+ * # Parameters
349
+ *
350
+ * - `client`: A valid client pointer.
351
+ * - `request_json`: NUL-terminated JSON string conforming to the
352
+ * `RerankRequest` schema.
353
+ *
354
+ * # Return value
355
+ *
356
+ * Returns a heap-allocated NUL-terminated JSON string containing the
357
+ * `RerankResponse` on success, or `NULL` on failure.
358
+ * The caller must free the returned string with [`literllm_free_string`].
359
+ *
360
+ * # Safety
361
+ *
362
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
363
+ * - `request_json` must be a valid, non-null, NUL-terminated UTF-8 JSON string.
364
+ */
365
+ LITER_LLM_EXPORT char *literllm_rerank(const LiterLlmClient *client, const char *request_json);
366
+
367
+ /**
368
+ * Perform a web/document search.
369
+ *
370
+ * # Parameters
371
+ *
372
+ * - `client`: A valid client pointer.
373
+ * - `request_json`: NUL-terminated JSON string conforming to the
374
+ * `SearchRequest` schema.
375
+ *
376
+ * # Return value
377
+ *
378
+ * Returns a heap-allocated NUL-terminated JSON string containing the
379
+ * `SearchResponse` on success, or `NULL` on failure.
380
+ * The caller must free the returned string with [`literllm_free_string`].
381
+ *
382
+ * # Safety
383
+ *
384
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
385
+ * - `request_json` must be a valid, non-null, NUL-terminated UTF-8 JSON string.
386
+ */
387
+ LITER_LLM_EXPORT char *literllm_search(const LiterLlmClient *client, const char *request_json);
388
+
389
+ /**
390
+ * Extract text from a document via OCR.
391
+ *
392
+ * # Parameters
393
+ *
394
+ * - `client`: A valid client pointer.
395
+ * - `request_json`: NUL-terminated JSON string conforming to the
396
+ * `OcrRequest` schema.
397
+ *
398
+ * # Return value
399
+ *
400
+ * Returns a heap-allocated NUL-terminated JSON string containing the
401
+ * `OcrResponse` on success, or `NULL` on failure.
402
+ * The caller must free the returned string with [`literllm_free_string`].
403
+ *
404
+ * # Safety
405
+ *
406
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
407
+ * - `request_json` must be a valid, non-null, NUL-terminated UTF-8 JSON string.
408
+ */
409
+ LITER_LLM_EXPORT char *literllm_ocr(const LiterLlmClient *client, const char *request_json);
410
+
411
+ /**
412
+ * Upload a file.
413
+ *
414
+ * # Parameters
415
+ *
416
+ * - `client`: A valid client pointer.
417
+ * - `request_json`: NUL-terminated JSON string conforming to the
418
+ * `CreateFileRequest` schema. The `file` field must be base64-encoded.
419
+ *
420
+ * # Return value
421
+ *
422
+ * Returns a heap-allocated NUL-terminated JSON string containing the
423
+ * `FileObject` on success, or `NULL` on failure.
424
+ * The caller must free the returned string with [`literllm_free_string`].
425
+ *
426
+ * # Safety
427
+ *
428
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
429
+ * - `request_json` must be a valid, non-null, NUL-terminated UTF-8 JSON string.
430
+ */
431
+ LITER_LLM_EXPORT char *literllm_create_file(const LiterLlmClient *client, const char *request_json);
432
+
433
+ /**
434
+ * Retrieve metadata for a file by ID.
435
+ *
436
+ * # Parameters
437
+ *
438
+ * - `client`: A valid client pointer.
439
+ * - `file_id`: NUL-terminated file ID string.
440
+ *
441
+ * # Return value
442
+ *
443
+ * Returns a heap-allocated NUL-terminated JSON string containing the
444
+ * `FileObject` on success, or `NULL` on failure.
445
+ * The caller must free the returned string with [`literllm_free_string`].
446
+ *
447
+ * # Safety
448
+ *
449
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
450
+ * - `file_id` must be a valid, non-null, NUL-terminated UTF-8 string.
451
+ */
452
+ LITER_LLM_EXPORT char *literllm_retrieve_file(const LiterLlmClient *client, const char *file_id);
453
+
454
+ /**
455
+ * Delete a file by ID.
456
+ *
457
+ * # Parameters
458
+ *
459
+ * - `client`: A valid client pointer.
460
+ * - `file_id`: NUL-terminated file ID string.
461
+ *
462
+ * # Return value
463
+ *
464
+ * Returns a heap-allocated NUL-terminated JSON string containing the
465
+ * `DeleteResponse` on success, or `NULL` on failure.
466
+ * The caller must free the returned string with [`literllm_free_string`].
467
+ *
468
+ * # Safety
469
+ *
470
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
471
+ * - `file_id` must be a valid, non-null, NUL-terminated UTF-8 string.
472
+ */
473
+ LITER_LLM_EXPORT char *literllm_delete_file(const LiterLlmClient *client, const char *file_id);
474
+
475
+ /**
476
+ * List files, optionally filtered by query parameters.
477
+ *
478
+ * # Parameters
479
+ *
480
+ * - `client`: A valid client pointer.
481
+ * - `query_json`: NUL-terminated JSON string conforming to the
482
+ * `FileListQuery` schema. May be `NULL` to list all files.
483
+ *
484
+ * # Return value
485
+ *
486
+ * Returns a heap-allocated NUL-terminated JSON string containing the
487
+ * `FileListResponse` on success, or `NULL` on failure.
488
+ * The caller must free the returned string with [`literllm_free_string`].
489
+ *
490
+ * # Safety
491
+ *
492
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
493
+ * - `query_json` may be `NULL` or a valid NUL-terminated UTF-8 JSON string.
494
+ */
495
+ LITER_LLM_EXPORT char *literllm_list_files(const LiterLlmClient *client, const char *query_json);
496
+
497
+ /**
498
+ * Retrieve the raw content of a file (returned as base64-encoded string).
499
+ *
500
+ * # Parameters
501
+ *
502
+ * - `client`: A valid client pointer.
503
+ * - `file_id`: NUL-terminated file ID string.
504
+ *
505
+ * # Return value
506
+ *
507
+ * Returns a heap-allocated NUL-terminated base64-encoded string of the file
508
+ * content on success, or `NULL` on failure.
509
+ * The caller must free the returned string with [`literllm_free_string`].
510
+ *
511
+ * # Safety
512
+ *
513
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
514
+ * - `file_id` must be a valid, non-null, NUL-terminated UTF-8 string.
515
+ */
516
+ LITER_LLM_EXPORT char *literllm_file_content(const LiterLlmClient *client, const char *file_id);
517
+
518
+ /**
519
+ * Create a new batch job.
520
+ *
521
+ * # Parameters
522
+ *
523
+ * - `client`: A valid client pointer.
524
+ * - `request_json`: NUL-terminated JSON string conforming to the
525
+ * `CreateBatchRequest` schema.
526
+ *
527
+ * # Return value
528
+ *
529
+ * Returns a heap-allocated NUL-terminated JSON string containing the
530
+ * `BatchObject` on success, or `NULL` on failure.
531
+ * The caller must free the returned string with [`literllm_free_string`].
532
+ *
533
+ * # Safety
534
+ *
535
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
536
+ * - `request_json` must be a valid, non-null, NUL-terminated UTF-8 JSON string.
537
+ */
538
+ LITER_LLM_EXPORT
539
+ char *literllm_create_batch(const LiterLlmClient *client,
540
+ const char *request_json);
541
+
542
+ /**
543
+ * Retrieve a batch by ID.
544
+ *
545
+ * # Parameters
546
+ *
547
+ * - `client`: A valid client pointer.
548
+ * - `batch_id`: NUL-terminated batch ID string.
549
+ *
550
+ * # Return value
551
+ *
552
+ * Returns a heap-allocated NUL-terminated JSON string containing the
553
+ * `BatchObject` on success, or `NULL` on failure.
554
+ * The caller must free the returned string with [`literllm_free_string`].
555
+ *
556
+ * # Safety
557
+ *
558
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
559
+ * - `batch_id` must be a valid, non-null, NUL-terminated UTF-8 string.
560
+ */
561
+ LITER_LLM_EXPORT char *literllm_retrieve_batch(const LiterLlmClient *client, const char *batch_id);
562
+
563
+ /**
564
+ * List batches, optionally filtered by query parameters.
565
+ *
566
+ * # Parameters
567
+ *
568
+ * - `client`: A valid client pointer.
569
+ * - `query_json`: NUL-terminated JSON string conforming to the
570
+ * `BatchListQuery` schema. May be `NULL` to list all batches.
571
+ *
572
+ * # Return value
573
+ *
574
+ * Returns a heap-allocated NUL-terminated JSON string containing the
575
+ * `BatchListResponse` on success, or `NULL` on failure.
576
+ * The caller must free the returned string with [`literllm_free_string`].
577
+ *
578
+ * # Safety
579
+ *
580
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
581
+ * - `query_json` may be `NULL` or a valid NUL-terminated UTF-8 JSON string.
582
+ */
583
+ LITER_LLM_EXPORT char *literllm_list_batches(const LiterLlmClient *client, const char *query_json);
584
+
585
+ /**
586
+ * Cancel an in-progress batch.
587
+ *
588
+ * # Parameters
589
+ *
590
+ * - `client`: A valid client pointer.
591
+ * - `batch_id`: NUL-terminated batch ID string.
592
+ *
593
+ * # Return value
594
+ *
595
+ * Returns a heap-allocated NUL-terminated JSON string containing the
596
+ * `BatchObject` on success, or `NULL` on failure.
597
+ * The caller must free the returned string with [`literllm_free_string`].
598
+ *
599
+ * # Safety
600
+ *
601
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
602
+ * - `batch_id` must be a valid, non-null, NUL-terminated UTF-8 string.
603
+ */
604
+ LITER_LLM_EXPORT char *literllm_cancel_batch(const LiterLlmClient *client, const char *batch_id);
605
+
606
+ /**
607
+ * Create a new response.
608
+ *
609
+ * # Parameters
610
+ *
611
+ * - `client`: A valid client pointer.
612
+ * - `request_json`: NUL-terminated JSON string conforming to the
613
+ * `CreateResponseRequest` schema.
614
+ *
615
+ * # Return value
616
+ *
617
+ * Returns a heap-allocated NUL-terminated JSON string containing the
618
+ * `ResponseObject` on success, or `NULL` on failure.
619
+ * The caller must free the returned string with [`literllm_free_string`].
620
+ *
621
+ * # Safety
622
+ *
623
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
624
+ * - `request_json` must be a valid, non-null, NUL-terminated UTF-8 JSON string.
625
+ */
626
+ LITER_LLM_EXPORT
627
+ char *literllm_create_response(const LiterLlmClient *client,
628
+ const char *request_json);
629
+
630
+ /**
631
+ * Retrieve a response by ID.
632
+ *
633
+ * # Parameters
634
+ *
635
+ * - `client`: A valid client pointer.
636
+ * - `response_id`: NUL-terminated response ID string.
637
+ *
638
+ * # Return value
639
+ *
640
+ * Returns a heap-allocated NUL-terminated JSON string containing the
641
+ * `ResponseObject` on success, or `NULL` on failure.
642
+ * The caller must free the returned string with [`literllm_free_string`].
643
+ *
644
+ * # Safety
645
+ *
646
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
647
+ * - `response_id` must be a valid, non-null, NUL-terminated UTF-8 string.
648
+ */
649
+ LITER_LLM_EXPORT
650
+ char *literllm_retrieve_response(const LiterLlmClient *client,
651
+ const char *response_id);
652
+
653
+ /**
654
+ * Cancel an in-progress response.
655
+ *
656
+ * # Parameters
657
+ *
658
+ * - `client`: A valid client pointer.
659
+ * - `response_id`: NUL-terminated response ID string.
660
+ *
661
+ * # Return value
662
+ *
663
+ * Returns a heap-allocated NUL-terminated JSON string containing the
664
+ * `ResponseObject` on success, or `NULL` on failure.
665
+ * The caller must free the returned string with [`literllm_free_string`].
666
+ *
667
+ * # Safety
668
+ *
669
+ * - `client` must be a valid, non-null pointer returned by `literllm_client_new`.
670
+ * - `response_id` must be a valid, non-null, NUL-terminated UTF-8 string.
671
+ */
672
+ LITER_LLM_EXPORT
673
+ char *literllm_cancel_response(const LiterLlmClient *client,
674
+ const char *response_id);
675
+
676
+ /**
677
+ * Read the cumulative global spend tracked by the budget layer.
678
+ *
679
+ * Returns the spend in USD. If no budget is configured on the client,
680
+ * returns `0.0`.
681
+ *
682
+ * # Safety
683
+ *
684
+ * - `client` must be a valid, non-null pointer returned by
685
+ * `literllm_client_new` or `literllm_client_new_with_config`.
686
+ */
687
+ LITER_LLM_EXPORT double literllm_budget_usage(const LiterLlmClient *client);
688
+
689
+ /**
690
+ * Retrieve the last error message for the current thread.
691
+ *
692
+ * Returns a `const char*` pointer to the NUL-terminated error string, or
693
+ * `NULL` if no error has occurred since the last successful call.
694
+ *
695
+ * The returned pointer is valid only until the **next** liter-llm function
696
+ * call on the **same thread**. The caller must **not** free this pointer.
697
+ *
698
+ * # Safety
699
+ *
700
+ * Always safe to call. No preconditions.
701
+ */
702
+ LITER_LLM_EXPORT const char *literllm_last_error(void);
703
+
704
+ /**
705
+ * Free a string returned by [`literllm_chat`], [`literllm_embed`], or
706
+ * [`literllm_list_models`].
707
+ *
708
+ * # Safety
709
+ *
710
+ * - `s` must be a pointer returned by one of the functions listed above.
711
+ * - `s` must not be used after this call (use-after-free is UB).
712
+ * - Passing `NULL` is safe and is a no-op.
713
+ * - Do **not** pass the pointer returned by [`literllm_last_error`]; that
714
+ * pointer must not be freed.
715
+ */
716
+ LITER_LLM_EXPORT void literllm_free_string(char *s);
717
+
718
+ /**
719
+ * Returns the version string of the liter-llm library.
720
+ *
721
+ * The returned pointer is valid for the lifetime of the program and must
722
+ * **not** be freed.
723
+ *
724
+ * # Safety
725
+ *
726
+ * Always safe to call.
727
+ */
728
+ LITER_LLM_EXPORT const char *literllm_version(void);
729
+
730
+ /**
731
+ * Register a custom LLM provider at runtime.
732
+ *
733
+ * # Parameters
734
+ *
735
+ * - `config_json`: NUL-terminated JSON string conforming to the
736
+ * [`CustomProviderConfig`](liter_llm::CustomProviderConfig) schema.
737
+ *
738
+ * # Return value
739
+ *
740
+ * Returns `0` on success, `-1` on failure.
741
+ * Check [`literllm_last_error`] for the error message when `-1` is returned.
742
+ *
743
+ * # Safety
744
+ *
745
+ * - `config_json` must be a valid, non-null, NUL-terminated UTF-8 JSON string.
746
+ */
747
+ LITER_LLM_EXPORT int32_t literllm_register_provider(const char *config_json);
748
+
749
+ /**
750
+ * Unregister a previously registered custom provider by name.
751
+ *
752
+ * # Parameters
753
+ *
754
+ * - `name`: NUL-terminated provider name string.
755
+ *
756
+ * # Return value
757
+ *
758
+ * Returns `0` if the provider was found and removed, `1` if no provider with
759
+ * that name existed, or `-1` on failure.
760
+ * Check [`literllm_last_error`] for the error message when `-1` is returned.
761
+ *
762
+ * # Safety
763
+ *
764
+ * - `name` must be a valid, non-null, NUL-terminated UTF-8 string.
765
+ */
766
+ LITER_LLM_EXPORT int32_t literllm_unregister_provider(const char *name);
767
+
768
+ /**
769
+ * Create a new liter-llm client from a full JSON configuration object.
770
+ *
771
+ * This is an extended version of [`literllm_client_new`] that accepts a
772
+ * single JSON string containing all configuration options, including
773
+ * cache, budget, extra headers, and model hint.
774
+ *
775
+ * # JSON Schema
776
+ *
777
+ * ```json
778
+ * {
779
+ * "api_key": "sk-...",
780
+ * "base_url": "https://...", // optional
781
+ * "model_hint": "groq/llama3-70b", // optional
782
+ * "max_retries": 3, // optional, default 3
783
+ * "timeout_secs": 60, // optional, default 60
784
+ * "extra_headers": {"X-Custom": "v"}, // optional
785
+ * "cache": { // optional
786
+ * "max_entries": 256,
787
+ * "ttl_secs": 300
788
+ * },
789
+ * "budget": { // optional
790
+ * "global_limit": 10.0,
791
+ * "model_limits": {"gpt-4": 5.0},
792
+ * "enforcement": "hard"
793
+ * }
794
+ * }
795
+ * ```
796
+ *
797
+ * # Return value
798
+ *
799
+ * Returns a heap-allocated `LiterLlmClient*` on success, or `NULL` on
800
+ * failure. Check [`literllm_last_error`] for the error message when
801
+ * `NULL` is returned.
802
+ *
803
+ * The returned pointer must be freed with [`literllm_client_free`].
804
+ *
805
+ * # Safety
806
+ *
807
+ * - `config_json` must be a valid, non-null, NUL-terminated UTF-8 JSON string.
808
+ * - The caller owns the returned pointer and must call `literllm_client_free`
809
+ * exactly once.
810
+ */
811
+ LITER_LLM_EXPORT LiterLlmClient *literllm_client_new_with_config(const char *config_json);
812
+
813
+ /**
814
+ * Register lifecycle hook callbacks for a client.
815
+ *
816
+ * The callbacks are stored for the lifetime of the client and invoked
817
+ * around each API call (chat, embed, etc.).
818
+ *
819
+ * **Note:** In the current implementation, hooks are advisory metadata
820
+ * stored on the client handle. Full Tower-integrated hook invocation
821
+ * requires the client to be wrapped in a `HooksLayer` service stack,
822
+ * which is an internal architecture detail. C FFI callers should use
823
+ * these callbacks as a notification mechanism; the Rust core handles
824
+ * the actual request lifecycle.
825
+ *
826
+ * # Parameters
827
+ *
828
+ * - `client`: A valid client pointer.
829
+ * - `callbacks`: Pointer to a `LiterLlmHookCallbacks` struct. The struct
830
+ * is copied; the caller may free it after this call returns.
831
+ *
832
+ * # Return value
833
+ *
834
+ * Returns `0` on success, `-1` on failure.
835
+ *
836
+ * # Safety
837
+ *
838
+ * - `client` must be a valid, non-null pointer returned by
839
+ * `literllm_client_new` or `literllm_client_new_with_config`.
840
+ * - `callbacks` must be a valid, non-null pointer to a
841
+ * `LiterLlmHookCallbacks` struct.
842
+ * - Function pointers in `callbacks` must remain valid for the lifetime
843
+ * of the client.
844
+ * - `user_data` must be valid for the lifetime of the client if non-NULL.
845
+ */
846
+ LITER_LLM_EXPORT
847
+ int32_t literllm_set_hooks(LiterLlmClient *client,
848
+ const struct LiterLlmHookCallbacks *callbacks);
849
+
850
+ #endif /* LITER_LLM_FFI_H */