litellm-api 2.4.0 → 2.5.1

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
@@ -47,6 +47,24 @@ const client = new LiteLLMApi({
47
47
  });
48
48
  ```
49
49
 
50
+ ### Line-delimited JSON
51
+
52
+ An operation that answers with line-delimited JSON (`application/x-ndjson` and similar), such as the Lens dataset export, resolves to an array with one parsed value per line once the body ends. To read each line as it arrives, for example from a stream the server keeps open, pass `jsonLines: "stream"` in `config` and iterate the result:
53
+
54
+ ```ts
55
+ import { isJsonLineStream } from "litellm-api";
56
+
57
+ const rows = await client.request("GET /lens/datasets/{dataset_id}/export", {
58
+ pathParams: { dataset_id: datasetId },
59
+ config: { jsonLines: "stream" },
60
+ });
61
+ if (isJsonLineStream(rows)) {
62
+ for await (const line of rows) console.log(line);
63
+ }
64
+ ```
65
+
66
+ Leaving the loop early cancels the response body. A response of another type resolves as usual, and so does any response when a custom `fetch` returns no `body`.
67
+
50
68
  ## Errors
51
69
 
52
70
  A call that gets an HTTP error response rejects with `{ status, payload }`: `status` is the HTTP status code and `payload` is the parsed JSON error body, or the raw body text, up to 1000 characters, when it is not JSON. A request that gets no response at all, for example because the network failed, rejects with an `Error` whose message names the method, the path and the reason, and whose `cause` is the original exception. A request cancelled through `signal` rejects with what the signal was aborted with, as is: the `AbortError`, or the `TimeoutError` of `AbortSignal.timeout()`.