llm-large-files 0.5.0 → 0.7.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/CHANGELOG.md +1402 -467
- package/README.md +188 -60
- package/dist/analyze.d.ts +5 -0
- package/dist/analyze.d.ts.map +1 -1
- package/dist/analyze.js +96 -47
- package/dist/analyze.js.map +1 -1
- package/dist/anthropic/adapter.d.ts +14 -3
- package/dist/anthropic/adapter.d.ts.map +1 -1
- package/dist/anthropic/adapter.js +190 -39
- package/dist/anthropic/adapter.js.map +1 -1
- package/dist/ask.d.ts +60 -4
- package/dist/ask.d.ts.map +1 -1
- package/dist/ask.js +1068 -206
- package/dist/ask.js.map +1 -1
- package/dist/encoding.d.ts +17 -0
- package/dist/encoding.d.ts.map +1 -0
- package/dist/encoding.js +852 -0
- package/dist/encoding.js.map +1 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +15 -0
- package/dist/errors.js.map +1 -1
- package/dist/events.d.ts +333 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +159 -0
- package/dist/events.js.map +1 -0
- package/dist/evidence.d.ts +2 -0
- package/dist/evidence.d.ts.map +1 -1
- package/dist/evidence.js +3 -2
- package/dist/evidence.js.map +1 -1
- package/dist/extract.d.ts +35 -3
- package/dist/extract.d.ts.map +1 -1
- package/dist/extract.js +626 -58
- package/dist/extract.js.map +1 -1
- package/dist/gemini/adapter.d.ts +17 -8
- package/dist/gemini/adapter.d.ts.map +1 -1
- package/dist/gemini/adapter.js +108 -61
- package/dist/gemini/adapter.js.map +1 -1
- package/dist/gemini/chat.d.ts +23 -3
- package/dist/gemini/chat.d.ts.map +1 -1
- package/dist/gemini/chat.js +6 -2
- package/dist/gemini/chat.js.map +1 -1
- package/dist/gemini/errors.d.ts +9 -4
- package/dist/gemini/errors.d.ts.map +1 -1
- package/dist/gemini/errors.js +32 -0
- package/dist/gemini/errors.js.map +1 -1
- package/dist/gemini/generate.d.ts +10 -2
- package/dist/gemini/generate.d.ts.map +1 -1
- package/dist/gemini/generate.js +13 -7
- package/dist/gemini/generate.js.map +1 -1
- package/dist/gemini/index.d.ts +3 -3
- package/dist/gemini/index.d.ts.map +1 -1
- package/dist/gemini/index.js +2 -2
- package/dist/gemini/index.js.map +1 -1
- package/dist/gemini/sse.d.ts +1 -1
- package/dist/gemini/sse.d.ts.map +1 -1
- package/dist/gemini/sse.js +1 -1
- package/dist/gemini/sse.js.map +1 -1
- package/dist/http.d.ts +116 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +347 -1
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +11 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/library.d.ts +67 -5
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +405 -85
- package/dist/library.js.map +1 -1
- package/dist/map-reduce.d.ts +28 -1
- package/dist/map-reduce.d.ts.map +1 -1
- package/dist/map-reduce.js +240 -52
- package/dist/map-reduce.js.map +1 -1
- package/dist/model.d.ts +84 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +182 -1
- package/dist/model.js.map +1 -1
- package/dist/node/handlers.d.ts +20 -4
- package/dist/node/handlers.d.ts.map +1 -1
- package/dist/node/handlers.js +122 -20
- package/dist/node/handlers.js.map +1 -1
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/sse.d.ts +59 -0
- package/dist/node/sse.d.ts.map +1 -0
- package/dist/node/sse.js +174 -0
- package/dist/node/sse.js.map +1 -0
- package/dist/openai/adapter.d.ts +29 -5
- package/dist/openai/adapter.d.ts.map +1 -1
- package/dist/openai/adapter.js +311 -37
- package/dist/openai/adapter.js.map +1 -1
- package/dist/output-limit.d.ts +14 -2
- package/dist/output-limit.d.ts.map +1 -1
- package/dist/output-limit.js +39 -10
- package/dist/output-limit.js.map +1 -1
- package/dist/pause.d.ts +24 -0
- package/dist/pause.d.ts.map +1 -0
- package/dist/pause.js +38 -0
- package/dist/pause.js.map +1 -0
- package/dist/pdf-pages.d.ts +32 -2
- package/dist/pdf-pages.d.ts.map +1 -1
- package/dist/pdf-pages.js +275 -14
- package/dist/pdf-pages.js.map +1 -1
- package/dist/pdf-pictures.d.ts +30 -3
- package/dist/pdf-pictures.d.ts.map +1 -1
- package/dist/pdf-pictures.js +50 -8
- package/dist/pdf-pictures.js.map +1 -1
- package/dist/pdf-work.d.ts +40 -0
- package/dist/pdf-work.d.ts.map +1 -0
- package/dist/pdf-work.js +734 -0
- package/dist/pdf-work.js.map +1 -0
- package/dist/plan.d.ts +22 -4
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +61 -12
- package/dist/plan.js.map +1 -1
- package/dist/retry.d.ts +23 -1
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +33 -3
- package/dist/retry.js.map +1 -1
- package/dist/search.d.ts +8 -2
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +60 -10
- package/dist/search.js.map +1 -1
- package/dist/sse.d.ts +35 -2
- package/dist/sse.d.ts.map +1 -1
- package/dist/sse.js +145 -31
- package/dist/sse.js.map +1 -1
- package/dist/stores.d.ts.map +1 -1
- package/dist/stores.js +5 -2
- package/dist/stores.js.map +1 -1
- package/dist/text-index.d.ts +6 -0
- package/dist/text-index.d.ts.map +1 -1
- package/dist/text-index.js +25 -8
- package/dist/text-index.js.map +1 -1
- package/dist/text.d.ts +62 -2
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +314 -14
- package/dist/text.js.map +1 -1
- package/dist/tools.d.ts +61 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +269 -42
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +102 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/zip-directory.d.ts +43 -0
- package/dist/zip-directory.d.ts.map +1 -0
- package/dist/zip-directory.js +130 -0
- package/dist/zip-directory.js.map +1 -0
- package/docs/README.md +288 -0
- package/docs/api.md +37 -381
- package/docs/configuration.md +28 -558
- package/docs/getting-started.md +407 -223
- package/docs/guides/anthropic.md +590 -0
- package/docs/guides/conversations.md +629 -0
- package/docs/guides/costs-and-limits.md +726 -0
- package/docs/guides/deployment.md +654 -0
- package/docs/guides/errors-and-reliability.md +735 -0
- package/docs/guides/explorer-model.md +399 -0
- package/docs/guides/openai-compatible.md +602 -0
- package/docs/guides/own-adapter-and-loop.md +1169 -0
- package/docs/guides/pdfs.md +971 -0
- package/docs/guides/storage.md +731 -0
- package/docs/guides/testing.md +1199 -0
- package/docs/guides/vertex-and-gemini.md +717 -0
- package/docs/guides/web-app.md +1589 -0
- package/docs/how-it-works.md +1012 -164
- package/docs/measurements.md +881 -0
- package/docs/publishing.md +274 -46
- package/docs/reference/anthropic.md +427 -0
- package/docs/reference/ask.md +892 -0
- package/docs/reference/errors-and-retries.md +758 -0
- package/docs/reference/events.md +993 -0
- package/docs/reference/gemini.md +823 -0
- package/docs/reference/library.md +1467 -0
- package/docs/reference/node.md +528 -0
- package/docs/reference/openai.md +385 -0
- package/docs/reference/tools.md +883 -0
- package/docs/security.md +897 -103
- package/docs/troubleshooting.md +1390 -0
- package/package.json +2 -2
- package/src/analyze.ts +93 -42
- package/src/anthropic/adapter.ts +196 -39
- package/src/ask.ts +1087 -202
- package/src/encoding.ts +850 -0
- package/src/errors.ts +17 -0
- package/src/events.ts +442 -0
- package/src/evidence.ts +5 -2
- package/src/extract.ts +602 -62
- package/src/gemini/adapter.ts +118 -65
- package/src/gemini/chat.ts +28 -4
- package/src/gemini/errors.ts +34 -1
- package/src/gemini/generate.ts +23 -10
- package/src/gemini/index.ts +3 -3
- package/src/gemini/sse.ts +1 -1
- package/src/http.ts +376 -1
- package/src/index.ts +27 -5
- package/src/library.ts +459 -85
- package/src/map-reduce.ts +252 -51
- package/src/model.ts +236 -3
- package/src/node/handlers.ts +137 -22
- package/src/node/index.ts +2 -0
- package/src/node/sse.ts +198 -0
- package/src/openai/adapter.ts +306 -38
- package/src/output-limit.ts +44 -8
- package/src/pause.ts +41 -0
- package/src/pdf-pages.ts +268 -15
- package/src/pdf-pictures.ts +56 -9
- package/src/pdf-work.ts +722 -0
- package/src/plan.ts +68 -12
- package/src/retry.ts +49 -5
- package/src/search.ts +63 -10
- package/src/sse.ts +153 -28
- package/src/stores.ts +5 -2
- package/src/text-index.ts +26 -7
- package/src/text.ts +323 -13
- package/src/tools.ts +261 -42
- package/src/types.ts +107 -4
- package/src/zip-directory.ts +136 -0
package/docs/api.md
CHANGED
|
@@ -1,446 +1,102 @@
|
|
|
1
1
|
# API reference
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The API reference is no longer one page. It is split by module of the package: one page for each
|
|
4
|
+
of the four other entry points, and four for the main entry, `llm-large-files`. This page keeps the headings of the old
|
|
5
|
+
page, so that links to them still work, and each one points to its new home. The guides that
|
|
6
|
+
explain each task are listed in the [documentation index](./README.md).
|
|
4
7
|
|
|
5
|
-
|
|
|
8
|
+
| Entry point | Reference |
|
|
6
9
|
|---|---|
|
|
7
|
-
| `llm-large-files` |
|
|
8
|
-
| `llm-large-files/gemini` | `gemini()`, `askGemini`, endpoints
|
|
9
|
-
| `llm-large-files/openai` | `openAiCompatible()`
|
|
10
|
-
| `llm-large-files/anthropic` | `anthropic()`
|
|
11
|
-
| `llm-large-files/node` |
|
|
10
|
+
| `llm-large-files` | [The library and its documents](./reference/library.md), [the tool loop and the adapter contract](./reference/ask.md), [errors, retries and streams](./reference/errors-and-retries.md), [the tools the model sees](./reference/tools.md) |
|
|
11
|
+
| `llm-large-files/gemini` | [Gemini API and Vertex AI: `gemini()`, `askGemini`, the endpoints](./reference/gemini.md) |
|
|
12
|
+
| `llm-large-files/openai` | [OpenAI-compatible endpoints: `openAiCompatible()`](./reference/openai.md) |
|
|
13
|
+
| `llm-large-files/anthropic` | [Claude: `anthropic()`](./reference/anthropic.md) |
|
|
14
|
+
| `llm-large-files/node` | [Node HTTP handlers: `createDocumentHandlers`](./reference/node.md) |
|
|
12
15
|
|
|
13
16
|
## `llm-large-files`
|
|
14
17
|
|
|
18
|
+
Now four pages: [the library and its documents](./reference/library.md), [the tool loop and the adapter contract](./reference/ask.md), [errors, retries and streams](./reference/errors-and-retries.md), and [the tools the model sees](./reference/tools.md).
|
|
19
|
+
|
|
15
20
|
### `createLargeFiles(options): LargeFiles`
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
|---|---|---|
|
|
19
|
-
| `store` | `DocumentStore` | required |
|
|
20
|
-
| `budget` | `Partial<Budget>` | see [configuration](configuration.md#budget). What is left out follows `contextTokens`; values that cannot work together throw |
|
|
21
|
-
| `ttlMs` | `number` | 72 hours. `Infinity` keeps documents until they are deleted (`expiresAt` is then `NEVER_EXPIRES`) |
|
|
22
|
-
| `maxUploadBytes` | `number` | 100 MB |
|
|
23
|
-
| `extractors` | `Partial<Record<DocumentFormat, Extractor>>` | built-ins |
|
|
24
|
-
| `cacheBytes` | `number` | 256 MB: memory that documents kept ready between tool calls may take. Each use checks the store first. 0 keeps none |
|
|
25
|
-
| `cacheSize` | `number` | no limit: also caps the number of documents kept. The pieces kept of a document read by range are not counted |
|
|
26
|
-
| `wholeDocumentBytes` | `number` | 2 MB: larger documents are read by range when the store can ([details](configuration.md#large-files-many-users-several-servers)). `Infinity` loads all whole |
|
|
27
|
-
| `scanChunkBytes` | `number` | 1 MB: text read and searched at a time, reading by range |
|
|
28
|
-
| `maxConcurrentScans` | `number` | 4: searches of a document read by range that run at once; the others wait |
|
|
29
|
-
| `keepOriginals` | `DocumentFormat[]` | `[]`: only text is kept. `["pdf"]` keeps uploaded PDFs, which `view_pages` needs ([details](configuration.md#keeping-the-uploaded-file)) |
|
|
30
|
-
| `scannedPdfPages` | `number` | 30: the longest PDF without any text that is accepted when its original is kept. 0 refuses them all |
|
|
22
|
+
Now [`createLargeFiles`](./reference/library.md#createlargefilesoptions) in the library reference, with every option in [`LargeFilesOptions`](./reference/library.md#largefilesoptions).
|
|
31
23
|
|
|
32
24
|
### `LargeFiles`
|
|
33
25
|
|
|
34
|
-
|
|
35
|
-
|---|---|
|
|
36
|
-
| `ingest({ name, mimeType?, bytes, owner? })` | Extracts, normalizes, profiles, and stores a file. Returns `DocumentMeta`. Throws an `Error` with a user-readable message for empty, oversized, binary, or text-less files. |
|
|
37
|
-
| `getMeta(id, { owner }?)` | `DocumentMeta`, or `undefined` if unknown, expired, or owned by someone else. |
|
|
38
|
-
| `getOriginal(id, { owner }?)` | The uploaded file as a `Uint8Array`, when it was kept. `undefined` otherwise, and for another owner. |
|
|
39
|
-
| `delete(id, { owner }?)` | `true` if deleted. |
|
|
40
|
-
| `sweep()` | Removes expired documents; returns the count. |
|
|
41
|
-
| `prepare(ids, base, { owner?, viewPages?, budget? }?)` | Plans one request. `base` is `{ tokens, bytes }` for everything else in the request. Returns `PreparedContext`. `viewPages: true` says that your loop can pass files to the model. `budget` changes budget fields for this request. |
|
|
42
|
-
| `tools(documents, { generate?, onProgress?, signal?, viewPages?, regexBudgetMs?, maxWholeDocumentReads?, retry?, budget? })` | A `ToolSet` scoped to these documents: make one for each question. `generate` enables `analyze_whole_document`, for documents small enough for it. `viewPages` (`true`, or a list of documents such as `prepared.viewable`) enables `view_pages`. `regexBudgetMs` (default 6,000) is the time the regex searches of the tool set may take together. `maxWholeDocumentReads` (default 1) is how often each document may be read whole. `retry` is how a part read that failed is sent again. |
|
|
43
|
-
| `budgetFor(overrides?, limits?)` | The budget for one request: the library's, with `overrides` in place of its fields, made to fit `limits` (`{ contextTokens?, maxRequestBytes? }` of a model). |
|
|
44
|
-
|
|
45
|
-
`getMeta`, `getOriginal`, `delete`, `prepare` and the tools read the store. When it cannot be read
|
|
46
|
-
(a volume that does not answer, a database that is down) they throw `DocumentStoreError`, and a
|
|
47
|
-
tool call answers with its message. That is not "the document is gone": retry. The message names
|
|
48
|
-
no path and no host; `error.cause` is what the store threw, for your log.
|
|
49
|
-
| `budget`, `maxUploadBytes` | The effective settings. |
|
|
26
|
+
Now [`LargeFiles`](./reference/library.md#largefiles) in the library reference, with the options of its methods and [`DocumentStoreError`](./reference/library.md#documentstoreerror).
|
|
50
27
|
|
|
51
28
|
### `PreparedContext`
|
|
52
29
|
|
|
53
|
-
|
|
54
|
-
{
|
|
55
|
-
plan: { inline: DocumentMeta[]; searchable: DocumentMeta[]; inlineTokens: number; inlineBytes: number };
|
|
56
|
-
blocks: Map<string, string>; // per document ID: full text (inline) or a summary card (searchable)
|
|
57
|
-
instruction: string; // add to the system prompt; empty when there is nothing to search or to look at
|
|
58
|
-
missing: string[]; // IDs not found (never uploaded, expired, or another owner's)
|
|
59
|
-
viewable: DocumentMeta[]; // PDFs whose pages view_pages can show; empty without viewPages: true
|
|
60
|
-
}
|
|
61
|
-
```
|
|
30
|
+
Now [`PreparedContext`](./reference/library.md#preparedcontext) and [`DocumentPlan`](./reference/library.md#documentplan) in the library reference.
|
|
62
31
|
|
|
63
32
|
### `ToolSet`
|
|
64
33
|
|
|
65
|
-
|
|
66
|
-
{
|
|
67
|
-
declarations: ToolDeclaration[]; // { name, description, parameters: JSON Schema }
|
|
68
|
-
has(name): boolean;
|
|
69
|
-
execute(name, args): Promise<ToolResult>; // errors come back as { error } for the model to read
|
|
70
|
-
executeWithFiles(name, args, { maxFileBytes?, maxPages?, maxResultCharacters? }?): Promise<{ result: ToolResult; files: ToolFile[] }>;
|
|
71
|
-
describe(name, args): string; // "Search app.log (exact) for “timeout”"
|
|
72
|
-
resultCharacters(name): number; // the most characters a result of this tool can have
|
|
73
|
-
}
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
`executeWithFiles` runs any tool. Its `files` (`{ name, mimeType, bytes }`) are empty for all but
|
|
77
|
-
`view_pages`. `execute("view_pages", …)` returns an error, because it has no place for the file.
|
|
78
|
-
`maxResultCharacters` is the room your request has left for this result, when that is less than
|
|
79
|
-
the tool's own cap: the result is cut to it and says where to go on.
|
|
80
|
-
|
|
81
|
-
A second `analyze_whole_document` of the same document by one tool set answers with an error that
|
|
82
|
-
tells the model to use the first answer (`maxWholeDocumentReads`).
|
|
83
|
-
|
|
84
|
-
| Tool | Arguments | Returns |
|
|
85
|
-
|---|---|---|
|
|
86
|
-
| `search_document` | `document_id`, `query`, `mode`: `keywords` (default) \| `exact` \| `regex`, `max_results`, `context_lines`, `case_sensitive` | `keywords`: ranked passages with numbered lines. `exact`/`regex`: matching lines and `total_matching_lines`. |
|
|
87
|
-
| `read_document` | `document_id`, `start_line`, `end_line?` | Up to 600 numbered lines, and `next_start_line` if there's more |
|
|
88
|
-
| `get_document_overview` | `document_id` | Format, size, outline, log profile, first and last lines |
|
|
89
|
-
| `analyze_whole_document` | `document_id`, `task` | `answer` from a map-reduce read, plus part counts |
|
|
90
|
-
| `view_pages` | `document_id`, `from_page`, `to_page?` | Up to 5 pages of a PDF as one PDF file, with `pages` ("12-14"), `total_pages`, `file` (its name), and `next_page` when fewer pages were given than asked. Declared only with `viewPages`, for PDFs whose original is kept. |
|
|
91
|
-
|
|
92
|
-
For a PDF that `view_pages` can show, the results of `search_document` and `read_document` also
|
|
93
|
-
carry page numbers: `page` on each matching line, `pages` on a passage and on a range that was read.
|
|
34
|
+
Now [`ToolSet`](./reference/tools.md#toolset); each tool's arguments, results and limits are in [Tools](./reference/tools.md).
|
|
94
35
|
|
|
95
36
|
### Stores
|
|
96
37
|
|
|
97
|
-
|
|
98
|
-
- `new FileDocumentStore(directory, { now?, orphanAgeMs? })`: `<id>.txt`, `<id>.json` and the line
|
|
99
|
-
index `<id>.idx` per document, and `<id>.bin` for a kept original. Safe for several servers on one
|
|
100
|
-
volume: files are written whole, large documents are read by range, and `sweep` leaves files
|
|
101
|
-
younger than `orphanAgeMs` (1 hour) that belong to no document yet.
|
|
102
|
-
- Implement `DocumentStore` (`put`, `get`, `getMeta`, `delete`, `sweep?`, `putOriginal?` with
|
|
103
|
-
`getOriginal?` to keep originals, and `readTextRange?` with `putIndex?` and `getIndex?` to read
|
|
104
|
-
large documents by range) for anything else.
|
|
38
|
+
Now [`DocumentStore`](./reference/library.md#documentstore), [`MemoryDocumentStore`](./reference/library.md#memorydocumentstore) and [`FileDocumentStore`](./reference/library.md#filedocumentstore) in the library reference; choosing a store and writing your own are in [Storage](./guides/storage.md).
|
|
105
39
|
|
|
106
40
|
### Helpers
|
|
107
41
|
|
|
108
|
-
|
|
109
|
-
- `toolResultSummary(label, result)`: `" — 12 matching lines"`, for step lists.
|
|
110
|
-
- `isDocumentId(value)`, `DOCUMENT_ID_PATTERN`.
|
|
111
|
-
- `estimateTokens(text)`, `utf8Bytes(text)`, `jsonBytes(text)`.
|
|
112
|
-
- `detectFormat(name, mimeType)`, `defaultExtractors`, `TOOL_NAMES`, `DEFAULT_BUDGET`,
|
|
113
|
-
`MAX_VIEW_PAGES` (5), `MAX_WHOLE_DOCUMENT_READS` (1).
|
|
114
|
-
- `resolveBudget(partial?, limits?)`: a whole `Budget` from the fields you give
|
|
115
|
-
(see [configuration](configuration.md#budget)).
|
|
116
|
-
- `evidenceOf(call, result)`, `stubResult(call, result)`, `mergeRanges(ranges)`: what a tool call
|
|
117
|
-
showed, the short stand-in for a result that is dropped, and line ranges made one. For a loop of
|
|
118
|
-
your own.
|
|
119
|
-
- `withRetry(run, { retry?, signal?, canRetry?, onRetry? })`, `isRetryableStatus(status)`,
|
|
120
|
-
`retryAfterMs(headers, body?)`: the retry rule of the loop, for an adapter or a loop of your own.
|
|
121
|
-
- `parseSseJson(stream)`: async iterator over the JSON events of a `text/event-stream` body.
|
|
122
|
-
- `createPdfExtractor({ tables?: boolean, pictures?: boolean })`: the built-in PDF extractor with
|
|
123
|
-
an option changed. `tables: false` gives the text in pdf.js order, without rebuilt tables
|
|
124
|
-
(see [PDF tables](configuration.md#pdf-tables)). `pictures: false` leaves out the line that marks
|
|
125
|
-
a page with a picture (see [Pictures in PDFs](configuration.md#pictures-in-pdfs)).
|
|
42
|
+
Each helper is now on the page of its module: text sizes, formats, extractors, budgets, document IDs and `toDocumentSummary` in [the library reference](./reference/library.md); `toolResultSummary` and the tool constants in [Tools](./reference/tools.md); `evidenceOf`, `stubResult`, `mergeRanges` and `partialResultOf` in [the tool loop reference](./reference/ask.md); retries, error kinds, `parseSseJson` and the waits of the adapters in [Errors, retries and streams](./reference/errors-and-retries.md).
|
|
126
43
|
|
|
127
44
|
### Key types
|
|
128
45
|
|
|
129
|
-
|
|
130
|
-
type DocumentFormat = "text" | "markdown" | "log" | "json" | "csv" | "pdf" | "docx" | "pptx";
|
|
131
|
-
|
|
132
|
-
type DocumentMeta = {
|
|
133
|
-
id: string; owner?: string; name: string; mimeType: string; format: DocumentFormat;
|
|
134
|
-
bytes: number; textBytes: number; characters: number; lines: number; estimatedTokens: number;
|
|
135
|
-
wrappedLines: number; pages?: number;
|
|
136
|
-
originalKept?: boolean; // the uploaded file is in the store next to the text
|
|
137
|
-
outline: { line: number; level: number; title: string }[];
|
|
138
|
-
logProfile?: { levels: Record<string, number>; firstTimestamp?: string; lastTimestamp?: string;
|
|
139
|
-
topIssues: { template: string; level: string; count: number; firstLine: number }[] };
|
|
140
|
-
createdAt: string; expiresAt: string;
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
type GenerateText = (request: {
|
|
144
|
-
system: string; prompt: string; maxOutputTokens: number; signal?: AbortSignal;
|
|
145
|
-
onTruncated?: () => void; // call it when the model stopped at maxOutputTokens
|
|
146
|
-
onUsage?: (usage: { inputTokens?: number; cachedInputTokens?: number; outputTokens?: number; thoughtTokens?: number }) => void;
|
|
147
|
-
// call it once for every request that was answered
|
|
148
|
-
}) => Promise<string>;
|
|
149
|
-
type Extractor = (bytes: Uint8Array, input: { name: string; mimeType: string; format: DocumentFormat; scannedPages?: number }) => Promise<{ text: string; pages?: number }>;
|
|
150
|
-
// scannedPages: set when a PDF without any text is welcome, with the most pages it may have.
|
|
151
|
-
|
|
152
|
-
type ToolFile = { name: string; mimeType: string; bytes: Uint8Array };
|
|
153
|
-
```
|
|
46
|
+
Now [`DocumentMeta`](./reference/library.md#documentmeta), [`DocumentSummary`](./reference/library.md#documentsummary), [`DocumentFormat`](./reference/library.md#documentformat), [`Extractor`](./reference/library.md#extractor) and [`ExtractedText`](./reference/library.md#extractedtext) in the library reference, [`GenerateText`](./reference/ask.md#generatetext) and [`ModelCapabilities`](./reference/ask.md#modelcapabilities) in the tool loop reference, and [`ToolFile`](./reference/tools.md#toolfile) in Tools.
|
|
154
47
|
|
|
155
48
|
## `askWithFiles(options): Promise<AskResult>`
|
|
156
49
|
|
|
157
|
-
|
|
158
|
-
limits of the request, and ends with a request that must be answered in text.
|
|
159
|
-
|
|
160
|
-
| Option | Description |
|
|
161
|
-
|---|---|
|
|
162
|
-
| `files`, `model`, `documentIds`, `messages` | Required. `model` is an adapter: `gemini()`, `openAiCompatible()`, `anthropic()`, or [your own](#your-own-adapter). |
|
|
163
|
-
| `explorer` | A second adapter, of any provider. It makes the tool calls and reads whole files in parts, and `model` writes the answer from what the tools returned. See [An explorer model](configuration.md#an-explorer-model). |
|
|
164
|
-
| `messages` | The conversation; the last must be the user's. Plain turns `{ role: "user" \| "assistant", text }`, the `toolTurns` an earlier question returned, and turns with parts in the provider's own form: `{ role, parts: [{ text }, { native: anImagePart }] }`. |
|
|
165
|
-
| `system` | System instruction; the tool guide is appended when needed. |
|
|
166
|
-
| `owner` | Only documents with this owner (or no owner) are used. |
|
|
167
|
-
| `documentPlacement` | `"first"` (default): document text and cards go at the start of the first user turn and stay there, so follow-up questions reuse the provider's prompt cache. `"last"`: appended to the latest user turn. |
|
|
168
|
-
| `limits` | `toolTurns` (12): the most chat requests for one question, counting the answer. `callsPerTurn` (8): the most tool calls of one turn that are run. `wholeDocumentReads` (1): how often each document may be read whole. `inputTokens`, `requests` (none): ceilings for the whole question, part reads included. |
|
|
169
|
-
| `retry` | `{ retries = 3, baseDelayMs = 500, maxDelayMs = 60_000 }`. See [Limits and retries](configuration.md#limits-and-retries). |
|
|
170
|
-
| `budget` | Budget fields for this question, in place of the library's. |
|
|
171
|
-
| `wholeDocumentAnalysis` | Default `true`. Set `false` to withhold the costly whole-file tool. |
|
|
172
|
-
| `viewPages` | Default `true`. Offers `view_pages` for PDFs whose original is kept, when every model of the question can be sent a file. |
|
|
173
|
-
| `onText`, `onActivity`, `onStep` | Answer text as it arrives, transient status, completed steps. |
|
|
174
|
-
| `signal` | Stops the question. |
|
|
175
|
-
|
|
176
|
-
Returns:
|
|
177
|
-
|
|
178
|
-
```ts
|
|
179
|
-
{
|
|
180
|
-
text: string; // everything the answering model wrote
|
|
181
|
-
answered: boolean; // false when its last turn had no text, or the prompt was refused
|
|
182
|
-
blockReason?: string;
|
|
183
|
-
steps: string[]; // "Search app.log (exact) for “timeout” — 12 matching lines"
|
|
184
|
-
evidence: Evidence[]; // per tool call: { tool, documentId, document, lines?, pages?, query?, mode?, totalMatchingLines?, whole? }
|
|
185
|
-
toolTurns: ToolTurn[]; // the tool rounds as plain JSON, to keep with the conversation
|
|
186
|
-
plan: DocumentPlan; // which documents went in whole and which were searched
|
|
187
|
-
budget: Budget; // the budget the question ran with
|
|
188
|
-
turns: number; // chat requests, an explorer's among them; part reads are not counted
|
|
189
|
-
finishReason?: string;
|
|
190
|
-
usage: { // every request that was answered, part reads included
|
|
191
|
-
requests: number; inputTokens: number; cachedInputTokens: number; outputTokens: number; thoughtTokens: number;
|
|
192
|
-
byModel: Record<string, { requests; inputTokens; cachedInputTokens; outputTokens; thoughtTokens }>;
|
|
193
|
-
};
|
|
194
|
-
lastUsage?: Record<string, unknown>; // the provider's own usage object of the last chat response
|
|
195
|
-
}
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
`inputTokens` counts every token of the prompts, those read from a cache included, and
|
|
199
|
-
`cachedInputTokens` is the part that was. `outputTokens` includes thoughts.
|
|
200
|
-
|
|
201
|
-
`answered` is `false` when the model's last turn had no text: the prompt was blocked
|
|
202
|
-
(`blockReason` says why), the reply was cut off before any text, or the model produced a malformed
|
|
203
|
-
tool call and the request for the answer came back empty too. `text` is then empty or holds only a
|
|
204
|
-
remark the model made before a tool call, so show your own message:
|
|
205
|
-
|
|
206
|
-
```ts
|
|
207
|
-
const result = await askWithFiles({ ... });
|
|
208
|
-
if (!result.answered) show(result.blockReason ? "The request was blocked." : "No answer this time. Try again.");
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
It throws `DocumentsNotFoundError` (`.ids`) before calling the model, `DocumentStoreError` when the
|
|
212
|
-
store could not be read (retry: the documents are not gone), `ModelRequestError` (`.status`, and
|
|
213
|
-
`.retryAfterMs` when the provider named a wait) for an HTTP error that another try did not mend,
|
|
214
|
-
and `Error` when the last message isn't the user's. `status` is 0 for a connection that failed.
|
|
215
|
-
Each adapter throws its own subclass: `GeminiRequestError`, `OpenAiRequestError`,
|
|
216
|
-
`AnthropicRequestError`.
|
|
50
|
+
Now [`askWithFiles`](./reference/ask.md#askwithfilesoptions), [`AskOptions`](./reference/ask.md#askoptions), [`AskLimits`](./reference/ask.md#asklimits) and [`AskResult`](./reference/ask.md#askresult). What it throws ([`DocumentsNotFoundError`](./reference/ask.md#documentsnotfounderror), [`DocumentStoreError`](./reference/library.md#documentstoreerror), and [`ModelRequestError`](./reference/errors-and-retries.md#modelrequesterror) with its [`ModelErrorKind`](./reference/errors-and-retries.md#modelerrorkind)) and [`partialResultOf`](./reference/ask.md#partialresultoferror) are on those pages; what to show a user is in [Errors and reliability](./guides/errors-and-reliability.md).
|
|
217
51
|
|
|
218
52
|
### Keeping what a question read
|
|
219
53
|
|
|
220
|
-
|
|
221
|
-
between the question and its answer, and pass them back:
|
|
222
|
-
|
|
223
|
-
```ts
|
|
224
|
-
const first = await askWithFiles({ files, model, documentIds, messages: [{ role: "user", text: question }] });
|
|
225
|
-
await saveTurn(sessionId, { question, toolTurns: first.toolTurns, answer: first.text });
|
|
226
|
-
|
|
227
|
-
// The next question of the conversation:
|
|
228
|
-
const messages = [
|
|
229
|
-
{ role: "user", text: question }, ...first.toolTurns, { role: "assistant", text: first.text },
|
|
230
|
-
{ role: "user", text: "And how long did recovery take?" },
|
|
231
|
-
];
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
The model then sees what it read before, and a follow-up is often answered without a new search.
|
|
235
|
-
The rounds are plain JSON and belong to no provider. The pages of a PDF are not in them: a stored
|
|
236
|
-
round says that they were shown. They count against the budget like any other part of the
|
|
237
|
-
conversation, and late in a long question the oldest are shortened first.
|
|
54
|
+
Now in [Conversations](./guides/conversations.md); the type is [`ToolTurn`](./reference/ask.md#toolturn).
|
|
238
55
|
|
|
239
56
|
### Your own adapter
|
|
240
57
|
|
|
241
|
-
|
|
242
|
-
import type { ModelAdapter } from "llm-large-files";
|
|
243
|
-
|
|
244
|
-
const model: ModelAdapter = {
|
|
245
|
-
id: "my-model", // names the model in usage totals
|
|
246
|
-
capabilities: { toolFiles: "none", pageTokens: 0 }, // and, when you know them: contextTokens, maxRequestBytes, outputTokens, tokenScale, appendOnly
|
|
247
|
-
async send(request, hooks) {
|
|
248
|
-
// request: { system, messages, tools?, toolChoice? }
|
|
249
|
-
// messages: { role: "user" | "assistant", parts: [{ text } | { native }] }
|
|
250
|
-
// | { role: "tools", calls, answers: [{ call, result, files? }], raw? }
|
|
251
|
-
// Turn them into your provider's request, post it with hooks.signal, and call hooks.onText
|
|
252
|
-
// with the text as it arrives.
|
|
253
|
-
return { text, calls: [{ id, name, args }], raw: theTurnAsYourProviderSentIt, finishReason, usage: { inputTokens, outputTokens } };
|
|
254
|
-
},
|
|
255
|
-
generateText: async ({ system, prompt, maxOutputTokens, signal, onUsage, onTruncated }) => "…", // optional: enables whole-file reads
|
|
256
|
-
};
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
- A `tools` message is one round: the model's calls and the results, in call order. `raw` is the
|
|
260
|
-
turn as your `send` returned it, given back only to the adapter that produced it. Without `raw`
|
|
261
|
-
(an explorer of another provider made the calls, or the round was stored), build the turn from
|
|
262
|
-
`calls`.
|
|
263
|
-
- `toolChoice: "none"` means the model must answer in text. The tools are still in `tools`, for a
|
|
264
|
-
provider that wants them declared next to earlier calls.
|
|
265
|
-
- Throw `ModelRequestError(message, status, { retryAfterMs })` for an HTTP error, with status 0
|
|
266
|
-
for a connection that failed. The loop retries the ones worth retrying.
|
|
267
|
-
- Give a call whose arguments did not parse a `problem`: the loop answers it with that message and
|
|
268
|
-
does not run it.
|
|
269
|
-
- `capabilities.toolFiles` says where a file from a tool goes (`"inside"` the result, `"beside"`
|
|
270
|
-
it, or `"none"`: `view_pages` is then not offered). `appendOnly: true` tells the loop never to
|
|
271
|
-
rewrite an earlier turn of the conversation.
|
|
58
|
+
Now in [Your own adapter and loop](./guides/own-adapter-and-loop.md); the contract is [`ModelAdapter`](./reference/ask.md#modeladapter).
|
|
272
59
|
|
|
273
60
|
## `llm-large-files/gemini`
|
|
274
61
|
|
|
275
|
-
|
|
62
|
+
Now [the `llm-large-files/gemini` reference](./reference/gemini.md); setting up the Gemini API or Vertex AI is in [Gemini API and Vertex AI](./guides/vertex-and-gemini.md).
|
|
276
63
|
|
|
277
|
-
|
|
278
|
-
`{ url, streamUrl?, headers }`; its `explorerUrl` is not used here, because an explorer is an
|
|
279
|
-
adapter of its own.
|
|
64
|
+
### `gemini(endpoint, options?): ModelAdapter`
|
|
280
65
|
|
|
281
|
-
|
|
282
|
-
|---|---|
|
|
283
|
-
| `generationConfig` | Sent with every chat request. |
|
|
284
|
-
| `toolFilePlacement` | `"inside"` (default) or `"beside"`: see [Where the pages go](configuration.md#where-the-pages-go-toolfileplacement). |
|
|
285
|
-
| `analysisConfig` | `(maxOutputTokens) => generationConfig` for whole-file part reads. |
|
|
286
|
-
| `contextTokens`, `maxRequestBytes` | The model's window and the largest request, when the budget of a question should follow them. |
|
|
287
|
-
| `pageTokens` | Tokens billed for one PDF page. Default 530. |
|
|
288
|
-
| `id`, `fetch` | The name in usage totals (default: the model in the URL), and a custom fetch. |
|
|
289
|
-
|
|
290
|
-
```ts
|
|
291
|
-
const model = gemini(geminiApi({ apiKey, model: "gemini-3.8-flash" }), { generationConfig: { temperature: 0.3 } });
|
|
292
|
-
const explorer = gemini(geminiApi({ apiKey, model: "gemini-3.5-flash-lite" }));
|
|
293
|
-
await askWithFiles({ files, model, explorer, documentIds, messages });
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
`fromGeminiContents(contents)` turns Gemini `contents` into `messages`, and
|
|
297
|
-
`geminiToolTurns(toolTurns)` gives stored tool rounds as `contents`.
|
|
66
|
+
Now in [the `llm-large-files/gemini` reference](./reference/gemini.md), with its options.
|
|
298
67
|
|
|
299
68
|
### `askGemini(options): Promise<AskGeminiResult>`
|
|
300
69
|
|
|
301
|
-
|
|
302
|
-
when it names one. It takes Gemini `contents` as well as `messages`.
|
|
303
|
-
|
|
304
|
-
| Option | Description |
|
|
305
|
-
|---|---|
|
|
306
|
-
| `files`, `endpoint`, `documentIds` | Required. |
|
|
307
|
-
| `messages` | `{ role: "user" \| "model" \| "assistant", text }[]`; the last must be the user's. |
|
|
308
|
-
| `contents` | Instead of `messages`: raw Gemini `contents` (images, inline PDFs…). Not mutated. |
|
|
309
|
-
| `system` | System instruction; the tool guide is appended when needed. |
|
|
310
|
-
| `generationConfig` | Sent with every chat request. |
|
|
311
|
-
| `explorerGenerationConfig` | The same, for the requests of an [explorer model](configuration.md#an-explorer-model). Defaults to `generationConfig`. Not used without an explorer. |
|
|
312
|
-
| `owner` | Only documents with this owner (or no owner) are used. |
|
|
313
|
-
| `documentPlacement` | `"first"` (default): document text and cards go at the start of the first user turn and stay there, so follow-up questions reuse Gemini's prompt cache. `"last"`: appended to the latest user turn, as in 0.1.0. |
|
|
314
|
-
| `limits`, `retry`, `budget` | As in `askWithFiles`. |
|
|
315
|
-
| `maxToolTurns` | `limits.toolTurns` under its older name. Default 12. The most requests for one question, counting the answer. If the model is still calling tools on the last one, it is sent with no tools so the model must answer. With an explorer model the answer is always the last request, so the explorer has one less. |
|
|
316
|
-
| `maxToolCallsPerTurn` | `limits.callsPerTurn` under its older name. Default 8. The most tool calls of one model turn that are run. The others are answered with an error that tells the model to send them again if it still needs them. |
|
|
317
|
-
| `wholeDocumentAnalysis` | Default `true`. Set `false` to withhold the costly whole-file tool. |
|
|
318
|
-
| `viewPages` | Default `true`. Offers `view_pages` for PDFs whose original is kept. It changes nothing for a library that keeps no originals. |
|
|
319
|
-
| `toolFilePlacement` | `"inside"` (default): the pages go in the function response itself, which Gemini 3 models read. `"beside"`: in a user turn of their own after the function responses, for Gemini 2.5, which does not see a file inside a function response. See [Where the pages go](configuration.md#where-the-pages-go-toolfileplacement). |
|
|
320
|
-
| `analysisConfig` | `(maxOutputTokens) => generationConfig` for whole-file part reads. The explorer model reads the parts when there is one, so write it for that model. Without it a part is asked for with `{ maxOutputTokens, temperature: 0.2 }`. A model that thinks counts its thoughts in that limit: a reply that it cut off that way is asked for again with 32,768, and later parts start there. |
|
|
321
|
-
| `onText`, `onActivity`, `onStep` | Streaming answer text, transient status, completed steps. |
|
|
322
|
-
| `fetch`, `signal` | Custom fetch (proxies, tests) and cancellation. |
|
|
323
|
-
|
|
324
|
-
Returns what `askWithFiles` returns. **`usage` is the total of the question since 0.5.0**; Gemini's
|
|
325
|
-
own `usageMetadata` of the last response, which `usage` was before, is `lastUsage`.
|
|
326
|
-
|
|
327
|
-
It throws what `askWithFiles` throws; the model's errors are `GeminiRequestError` (`.status`, 0
|
|
328
|
-
for a connection that failed).
|
|
329
|
-
|
|
330
|
-
With an [explorer model](configuration.md#an-explorer-model), `text` and `onText` carry only what
|
|
331
|
-
the answering model wrote, `turns` counts the requests of both models, `usage.byModel` has an
|
|
332
|
-
entry for each, and `finishReason` and `lastUsage` are those of the answer. An explorer that
|
|
333
|
-
fails throws `GeminiRequestError` too.
|
|
70
|
+
Now in [the `llm-large-files/gemini` reference](./reference/gemini.md), with its options and its result.
|
|
334
71
|
|
|
335
72
|
### Endpoints
|
|
336
73
|
|
|
337
|
-
|
|
338
|
-
- `vertexAi({ project, model, explorerModel?, location = "global", accessToken, apiVersion = "v1" })`,
|
|
339
|
-
where `accessToken` can be a string or `() => string | Promise<string>`.
|
|
340
|
-
- Or any `{ url, streamUrl?, headers, explorerUrl? }` (`headers` can be a function).
|
|
341
|
-
|
|
342
|
-
`model` is the model that answers. `explorerModel` names a second one that makes the tool calls and
|
|
343
|
-
reads whole files in parts, so that `model` only writes the answer. Left out, empty, or the same as
|
|
344
|
-
`model`, one model does both, as before. In an endpoint of your own it is `explorerUrl`: the
|
|
345
|
-
`...:generateContent` URL of the explorer, called with the same headers. See
|
|
346
|
-
[An explorer model](configuration.md#an-explorer-model).
|
|
74
|
+
`geminiApi`, `vertexAi`, `vertexHost` and the `GeminiEndpoint` type (an endpoint of your own) are now in [the `llm-large-files/gemini` reference](./reference/gemini.md); access tokens and gateways are in [Gemini API and Vertex AI](./guides/vertex-and-gemini.md).
|
|
347
75
|
|
|
348
76
|
### Lower-level helpers
|
|
349
77
|
|
|
350
|
-
|
|
351
|
-
- `toGeminiTools(declarations)`: `{ functionDeclarations }`.
|
|
352
|
-
- `geminiFunctionResponses([{ call, result, files? }])`: the `user` turn answering function
|
|
353
|
-
calls. Files from `executeWithFiles` go inside their function response, as base64.
|
|
354
|
-
- `geminiFunctionResponseTurns([{ call, result, files? }], { files?: "inside" | "beside" })`: the
|
|
355
|
-
turns to add to `contents`. That is the one turn above, or with `"beside"` the function
|
|
356
|
-
responses followed by a `user` turn that holds the files.
|
|
357
|
-
- `FINAL_ANSWER_REQUEST`, `FINAL_ANSWER_AFTER_PAGES`: the messages `askGemini` adds when the model
|
|
358
|
-
must stop using tools. The second is used when `view_pages` was the only tool.
|
|
359
|
-
- `FINAL_ANSWER_WITHOUT_TOOLS`, `EXPLORER_INSTRUCTION`: the two texts `askGemini` adds for an
|
|
360
|
-
explorer model. The first asks the answering model for the answer when the explorer called no
|
|
361
|
-
tool. The second is the line in the explorer's system instruction that says what its part is.
|
|
362
|
-
- `parseSseJson(stream)`: async iterator over a Generate Content SSE stream.
|
|
78
|
+
`createGeminiGenerateText`, `toGeminiTools`, `geminiFunctionResponses` and `geminiFunctionResponseTurns` are now in [the `llm-large-files/gemini` reference](./reference/gemini.md); `FINAL_ANSWER_REQUEST`, `FINAL_ANSWER_AFTER_PAGES`, `FINAL_ANSWER_WITHOUT_TOOLS` and `EXPLORER_INSTRUCTION` in [the tool loop reference](./reference/ask.md); `parseSseJson` in [Errors, retries and streams](./reference/errors-and-retries.md); `llm-large-files/gemini` still exports them all, as [its reference](./reference/gemini.md) lists.
|
|
363
79
|
|
|
364
80
|
## `llm-large-files/openai`
|
|
365
81
|
|
|
366
|
-
|
|
82
|
+
Now [the `llm-large-files/openai` reference](./reference/openai.md); recipes for OpenAI, Azure OpenAI, DeepSeek, OpenRouter, vLLM, Ollama, LiteLLM and llama.cpp are in [OpenAI-compatible endpoints](./guides/openai-compatible.md).
|
|
367
83
|
|
|
368
|
-
|
|
369
|
-
Gemini's OpenAI layer.
|
|
84
|
+
### `openAiCompatible(options): ModelAdapter`
|
|
370
85
|
|
|
371
|
-
|
|
372
|
-
|---|---|
|
|
373
|
-
| `model` | Required: the model name the endpoint knows. |
|
|
374
|
-
| `baseUrl` | `/chat/completions` is added to it. Default `https://api.openai.com/v1`. |
|
|
375
|
-
| `url` | The whole URL, when it is not `baseUrl` + `/chat/completions` (Azure, a gateway). |
|
|
376
|
-
| `apiKey`, `headers` | `Authorization: Bearer …`, and more headers. A function is called for each request. |
|
|
377
|
-
| `body` | More fields for every chat request: `temperature`, `reasoning_effort`, `max_completion_tokens`. |
|
|
378
|
-
| `analysisBody` | `(maxOutputTokens) => fields` for whole-file part reads. |
|
|
379
|
-
| `maxTokensField` | The name of the output limit in a part read. Default `max_completion_tokens` for api.openai.com and Azure OpenAI, `max_tokens` elsewhere. |
|
|
380
|
-
| `answerWithoutTools` | `"tool_choice"` (default): the request for the answer keeps the tools and sends `tool_choice: "none"`. `"omit"`: it leaves them out, for a server that does not know `tool_choice`. |
|
|
381
|
-
| `pdfInput` | Default `false`. Send the pages of `view_pages` as a `file` part in a user message after the tool results. For a model that reads PDF input: many servers behind this API do not (Gemini's layer answers HTTP 400). Not run against OpenAI itself. |
|
|
382
|
-
| `stream`, `systemRole` | `false` for a server without streaming; `"developer"` for one that wants the newer role name. |
|
|
383
|
-
| `contextTokens`, `maxRequestBytes`, `tokenScale`, `pageTokens` | What the model takes, when the budget should follow it. |
|
|
384
|
-
| `id`, `timeoutMs`, `fetch` | The name in usage totals, the time a part read may take (180 s), a custom fetch. |
|
|
385
|
-
|
|
386
|
-
The model's own message goes back to it as it came (a server may want its `reasoning_content` or a
|
|
387
|
-
signature again). `fromOpenAiMessages(history)` returns `{ system, messages }` for a history kept
|
|
388
|
-
as Chat Completions messages, and `openAiToolTurns(toolTurns)` gives stored rounds in that form.
|
|
86
|
+
Now in [the `llm-large-files/openai` reference](./reference/openai.md), with its options.
|
|
389
87
|
|
|
390
88
|
## `llm-large-files/anthropic`
|
|
391
89
|
|
|
90
|
+
Now [the `llm-large-files/anthropic` reference](./reference/anthropic.md); setting up Claude is in [Claude](./guides/anthropic.md).
|
|
91
|
+
|
|
392
92
|
### `anthropic(options): ModelAdapter`
|
|
393
93
|
|
|
394
|
-
|
|
395
|
-
the request and response shapes of its documentation.
|
|
396
|
-
|
|
397
|
-
| Option | Description |
|
|
398
|
-
|---|---|
|
|
399
|
-
| `model` | Required: `"claude-opus-5-5"`. |
|
|
400
|
-
| `apiKey`, `authToken` | `x-api-key`, or `Authorization: Bearer …`. A function is called for each request. |
|
|
401
|
-
| `baseUrl`, `url`, `headers`, `version`, `betas` | For a gateway that speaks the same API: `/v1/messages` is added to `baseUrl`. `version` is the `anthropic-version` header (default `2026-10-21`). |
|
|
402
|
-
| `maxTokens` | `max_tokens` of a chat request. Default 64,000. It comes out of the context window, so the budget of a question keeps it free. |
|
|
403
|
-
| `body` | More fields for every chat request: `thinking`, `output_config`, `context_management`. |
|
|
404
|
-
| `analysisBody` | `(maxOutputTokens) => fields` for whole-file part reads, such as `{ output_config: { effort: "low" } }`. |
|
|
405
|
-
| `fallbacks` | `"default"`, or a list of `{ model }`: another model answers when a safety classifier declines the request. Off unless set: it adds a beta header that Bedrock, Vertex AI and Foundry do not take. |
|
|
406
|
-
| `cache` | Prompt caching. `true` (default) for five minutes, `"1h"`, or `false`. A cache write costs a quarter more than plain input, and a read a tenth. |
|
|
407
|
-
| `toolFilePlacement` | `"inside"` (default): pages go into the tool result as a document block. `"beside"`: after the tool results. `"none"`: `view_pages` is not offered. |
|
|
408
|
-
| `stream` | Default `true`: chat requests are streamed, which keeps a long reply from timing out. |
|
|
409
|
-
| `contextTokens`, `maxRequestBytes`, `pageTokens`, `tokenScale` | Defaults: none, 32 MB, 3,500, and 1.35 (a guess for the current tokenizer, corrected during a question by the count the API reports). |
|
|
410
|
-
| `id`, `timeoutMs`, `fetch` | As above. |
|
|
411
|
-
|
|
412
|
-
What the adapter takes care of:
|
|
413
|
-
|
|
414
|
-
- The model's turn goes back exactly as it came, thinking blocks included, and the conversation is
|
|
415
|
-
never rewritten: Claude checks its thinking blocks against the conversation they were written
|
|
416
|
-
in. So old tool results are not shortened for Claude. When the room runs out, the next request is
|
|
417
|
-
the answer. For long conversations, turn on the API's own clearing of old tool results with
|
|
418
|
-
`body: { context_management: … }` and its beta in `betas`.
|
|
419
|
-
- The request for the answer keeps the tools and sends `tool_choice: { type: "none" }`.
|
|
420
|
-
- A refusal (`stop_reason: "refusal"`) is `blockReason: "refusal: <category>"`.
|
|
421
|
-
- No sampling settings are sent: the API of this version refuses `temperature`.
|
|
422
|
-
|
|
423
|
-
`fromAnthropicMessages(history)` and `anthropicToolTurns(toolTurns)` convert a history kept as
|
|
424
|
-
Messages API messages.
|
|
94
|
+
Now in [the `llm-large-files/anthropic` reference](./reference/anthropic.md), with its options.
|
|
425
95
|
|
|
426
96
|
## `llm-large-files/node`
|
|
427
97
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
Returns `{ upload(req, res), get(req, res, id), remove(req, res, id) }`.
|
|
98
|
+
Now [the `llm-large-files/node` reference](./reference/node.md); uploads and streamed answers are in [Web app](./guides/web-app.md).
|
|
431
99
|
|
|
432
|
-
|
|
433
|
-
`?name=` query parameter, and optionally set `X-File-Type`. Responds 201 with a `DocumentSummary`,
|
|
434
|
-
or 400/413/422/500 with `{ error }`. If a framework already parsed the body into a `Buffer`
|
|
435
|
-
(`express.raw()`), that buffer is used.
|
|
436
|
-
- **get**: 200 with a `DocumentSummary`, or 404.
|
|
437
|
-
- **remove**: `{ deleted: boolean }`.
|
|
438
|
-
|
|
439
|
-
Each handler answers its errors itself and never rejects, so it needs no `catch`. 422 is a file
|
|
440
|
-
that cannot be read. 500 is the server's trouble, such as a store that fails: the message says
|
|
441
|
-
what failed and gives a system error's code (`Upload failed (ENOSPC).`), never a path or a host.
|
|
100
|
+
### `createDocumentHandlers(files, { getOwner? })`
|
|
442
101
|
|
|
443
|
-
|
|
444
|
-
(or `statusCode`) between 400 and 599, as the `http-errors` package makes:
|
|
445
|
-
`throw Object.assign(new Error("Sign in first."), { status: 401 })`. The handler answers with that
|
|
446
|
-
status and message. Any other error from `getOwner` is a 500 that does not repeat its message.
|
|
102
|
+
Now in [the `llm-large-files/node` reference](./reference/node.md), with its options, routes and statuses.
|