@nixet/sdk 0.0.0-stage → 0.1.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/LICENSE +21 -0
  3. package/README.md +870 -2
  4. package/SECURITY.md +30 -0
  5. package/api.md +485 -0
  6. package/dist/cjs/errors.d.ts +37 -0
  7. package/dist/cjs/errors.js +79 -0
  8. package/dist/cjs/index.d.ts +89 -0
  9. package/dist/cjs/index.js +118 -0
  10. package/dist/cjs/resources/agents.d.ts +67 -0
  11. package/dist/cjs/resources/agents.js +74 -0
  12. package/dist/cjs/resources/connections.d.ts +94 -0
  13. package/dist/cjs/resources/connections.js +106 -0
  14. package/dist/cjs/resources/conversations.d.ts +62 -0
  15. package/dist/cjs/resources/conversations.js +86 -0
  16. package/dist/cjs/resources/documents.d.ts +65 -0
  17. package/dist/cjs/resources/documents.js +61 -0
  18. package/dist/cjs/resources/guardrails.d.ts +56 -0
  19. package/dist/cjs/resources/guardrails.js +76 -0
  20. package/dist/cjs/resources/knowledge.d.ts +189 -0
  21. package/dist/cjs/resources/knowledge.js +218 -0
  22. package/dist/cjs/resources/mcp-servers.d.ts +83 -0
  23. package/dist/cjs/resources/mcp-servers.js +107 -0
  24. package/dist/cjs/resources/memory.d.ts +95 -0
  25. package/dist/cjs/resources/memory.js +127 -0
  26. package/dist/cjs/resources/runs.d.ts +78 -0
  27. package/dist/cjs/resources/runs.js +87 -0
  28. package/dist/cjs/resources/secrets.d.ts +60 -0
  29. package/dist/cjs/resources/secrets.js +85 -0
  30. package/dist/cjs/resources/skills.d.ts +57 -0
  31. package/dist/cjs/resources/skills.js +78 -0
  32. package/dist/cjs/resources/tasks.d.ts +91 -0
  33. package/dist/cjs/resources/tasks.js +129 -0
  34. package/dist/cjs/resources/tools.d.ts +42 -0
  35. package/dist/cjs/resources/tools.js +57 -0
  36. package/dist/cjs/resources/users.d.ts +39 -0
  37. package/dist/cjs/resources/users.js +57 -0
  38. package/dist/cjs/resources/versions.d.ts +105 -0
  39. package/dist/cjs/resources/versions.js +78 -0
  40. package/dist/cjs/stream.d.ts +57 -0
  41. package/dist/cjs/stream.js +170 -0
  42. package/dist/cjs/transport.d.ts +45 -0
  43. package/dist/cjs/transport.js +106 -0
  44. package/dist/cjs/types.d.ts +537 -0
  45. package/dist/cjs/types.js +3 -0
  46. package/dist/esm/errors.js +66 -0
  47. package/dist/esm/index.js +103 -0
  48. package/dist/esm/package.json +1 -0
  49. package/dist/esm/resources/agents.js +70 -0
  50. package/dist/esm/resources/connections.js +102 -0
  51. package/dist/esm/resources/conversations.js +82 -0
  52. package/dist/esm/resources/documents.js +57 -0
  53. package/dist/esm/resources/guardrails.js +72 -0
  54. package/dist/esm/resources/knowledge.js +212 -0
  55. package/dist/esm/resources/mcp-servers.js +103 -0
  56. package/dist/esm/resources/memory.js +123 -0
  57. package/dist/esm/resources/runs.js +83 -0
  58. package/dist/esm/resources/secrets.js +81 -0
  59. package/dist/esm/resources/skills.js +74 -0
  60. package/dist/esm/resources/tasks.js +125 -0
  61. package/dist/esm/resources/tools.js +53 -0
  62. package/dist/esm/resources/users.js +53 -0
  63. package/dist/esm/resources/versions.js +74 -0
  64. package/dist/esm/stream.js +166 -0
  65. package/dist/esm/transport.js +102 -0
  66. package/dist/esm/types.js +2 -0
  67. package/package.json +59 -4
package/README.md CHANGED
@@ -1,3 +1,871 @@
1
- # Temporary Holding Version
1
+ # Nixet TypeScript SDK
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/@nixet/sdk.svg)](https://www.npmjs.com/package/@nixet/sdk)
4
+ [![license](https://img.shields.io/npm/l/@nixet/sdk.svg)](./LICENSE)
5
+
6
+ The official TypeScript and JavaScript client for the [Nixet](https://nixet.ai) agent API.
7
+
8
+ Nixet runs agents for you. You create an agent, publish an immutable version of
9
+ its configuration, and run it — synchronously, as a stream, or as a background
10
+ task. This SDK covers the whole public API: agents and versions, runs and their
11
+ event logs, conversations, users, memory, skills, knowledge, MCP servers and
12
+ tools, per-user connections, guardrails, secrets, and document conversion.
13
+
14
+ The full method reference is in [api.md](./api.md). Release notes are in
15
+ [CHANGELOG.md](./CHANGELOG.md).
16
+
17
+ ## Contents
18
+
19
+ - [Installation](#installation)
20
+ - [Quick start](#quick-start)
21
+ - [Authentication and configuration](#authentication-and-configuration)
22
+ - [Agents and versions](#agents-and-versions)
23
+ - [Models](#models)
24
+ - [Built-in tools](#built-in-tools)
25
+ - [Runs](#runs)
26
+ - [Streaming](#streaming)
27
+ - [Variables](#variables)
28
+ - [Tasks](#tasks)
29
+ - [Users](#users)
30
+ - [Conversations](#conversations)
31
+ - [Memory](#memory)
32
+ - [Skills](#skills)
33
+ - [Knowledge](#knowledge)
34
+ - [Document conversion](#document-conversion)
35
+ - [MCP servers and tools](#mcp-servers-and-tools)
36
+ - [Per-user connections](#per-user-connections)
37
+ - [Guardrails](#guardrails)
38
+ - [Redaction](#redaction)
39
+ - [Secrets](#secrets)
40
+ - [Pagination](#pagination)
41
+ - [Errors](#errors)
42
+ - [Retries, timeouts and cancellation](#retries-timeouts-and-cancellation)
43
+ - [TypeScript](#typescript)
44
+ - [Use with Claude Code and Codex](#use-with-claude-code-and-codex)
45
+ - [Requirements](#requirements)
46
+
47
+ ## Installation
48
+
49
+ ```bash
50
+ npm install @nixet/sdk
51
+ # or
52
+ pnpm add @nixet/sdk
53
+ yarn add @nixet/sdk
54
+ bun add @nixet/sdk
55
+ ```
56
+
57
+ The SDK has one dependency, [`@nixet/contracts`](https://www.npmjs.com/package/@nixet/contracts),
58
+ which carries the request and response types shared with the API.
59
+
60
+ ## Quick start
61
+
62
+ ```ts
63
+ import { Nixet } from "@nixet/sdk";
64
+
65
+ const nixet = new Nixet(); // reads NIXET_API_KEY
66
+
67
+ const agent = await nixet.agents.create({
68
+ name: "Support Assistant",
69
+ instructions: "You are concise. Use tools for arithmetic.",
70
+ tools: ["calculate"],
71
+ });
72
+
73
+ const run = await nixet.runs.create(agent.id, { input: "What is 23 × 7?" });
74
+
75
+ console.log(run.output); // "23 times 7 is **161**."
76
+ console.log(run.usage); // token counts
77
+ console.log(run.cost_usd); // what the run cost
78
+ ```
79
+
80
+ ## Authentication and configuration
81
+
82
+ Create an API key in the [Nixet console](https://console.nixet.ai) under
83
+ **API keys**. A key is bound to one workspace and one environment
84
+ (`development` or `production`), so there is no workspace or project ID to pass.
85
+
86
+ ```ts
87
+ import { Nixet } from "@nixet/sdk";
88
+
89
+ const nixet = new Nixet({
90
+ apiKey: "nxt_…", // default: process.env.NIXET_API_KEY
91
+ baseURL: "https://api.nixet.ai/v1", // default: process.env.NIXET_BASE_URL, then this
92
+ timeout: 600_000, // ms; default 10 minutes, since a run waits on a model
93
+ maxRetries: 2, // default 2
94
+ fetch: customFetch, // default: globalThis.fetch
95
+ });
96
+ ```
97
+
98
+ | Option | Environment variable | Default |
99
+ | --- | --- | --- |
100
+ | `apiKey` | `NIXET_API_KEY` | required |
101
+ | `baseURL` | `NIXET_BASE_URL` | `https://api.nixet.ai/v1` |
102
+ | `timeout` | — | `600000` |
103
+ | `maxRetries` | — | `2` |
104
+ | `fetch` | — | `globalThis.fetch` |
105
+
106
+ Check what a key can do:
107
+
108
+ ```ts
109
+ const me = await nixet.whoami();
110
+ // { key_id, organization_id, project_id, environment_id, permissions: [...] }
111
+ ```
112
+
113
+ > Keep API keys on the server. Do not ship one in browser or mobile code.
114
+
115
+ ## Agents and versions
116
+
117
+ An agent is an identity. Its behaviour — instructions, model, tools, skills,
118
+ knowledge, guardrails — lives in **versions**, which are numbered (`v1`, `v2`, …)
119
+ and never edited. A past run can always be explained by the version it recorded.
120
+
121
+ `agents.create` publishes the first version for you when you pass `instructions`:
122
+
123
+ ```ts
124
+ const agent = await nixet.agents.create({
125
+ name: "Research Assistant",
126
+ description: "Answers questions with sources.",
127
+ instructions: "Cite every claim.",
128
+ model: { provider: "nix", tier: "powerful" },
129
+ tools: ["web_search", "fetch_url"],
130
+ });
131
+
132
+ agent.current_version; // "v1"
133
+ agent.version; // the AgentVersion that was published
134
+ ```
135
+
136
+ Publish a new version later. New runs use it immediately; runs already in
137
+ flight keep the version they started with.
138
+
139
+ ```ts
140
+ await nixet.agents.versions.create(agent.id, {
141
+ instructions: "Cite every claim, and say when you are unsure.",
142
+ tools: ["web_search", "fetch_url"],
143
+ });
144
+
145
+ // Stage a version without making it the default
146
+ await nixet.agents.versions.create(agent.id, { instructions: "…", publish: false });
147
+
148
+ const v1 = await nixet.agents.versions.retrieve(agent.id, "v1");
149
+ const versions = await nixet.agents.versions.list(agent.id);
150
+ ```
151
+
152
+ Everything a version can carry:
153
+
154
+ | Field | Purpose |
155
+ | --- | --- |
156
+ | `instructions` | The system prompt. Required. |
157
+ | `model` | Provider and tier or model name. See [Models](#models). |
158
+ | `tools` | Built-in tool names. See [Built-in tools](#built-in-tools). |
159
+ | `skills` | Skills as `name` or `name@v2`. See [Skills](#skills). |
160
+ | `mcpServers` | Registered MCP servers this version may use. |
161
+ | `toolPolicies` | Per-tool `allow` / `deny`, as `server.tool`. |
162
+ | `knowledgeCollections` | Knowledge collections this version may search. |
163
+ | `variables` | `{{placeholders}}` a run must fill. See [Variables](#variables). |
164
+ | `guardrails` | Guardrails per stage. See [Guardrails](#guardrails). |
165
+ | `redaction` | Mask personal data. See [Redaction](#redaction). |
166
+ | `publish` | Make this the default version. Defaults to `true`. |
167
+
168
+ Configuration is checked when you publish, not when you run: an unknown tool, a
169
+ missing MCP server, or a placeholder used but not declared is refused at
170
+ publish with a `BadRequestError`.
171
+
172
+ ## Models
173
+
174
+ The managed provider, `nix`, needs no key of your own. You choose a capability
175
+ tier rather than a model:
176
+
177
+ ```ts
178
+ model: { provider: "nix", tier: "fast" } // fast | balanced | powerful
179
+ ```
180
+
181
+ To name a specific model, use its provider:
182
+
183
+ ```ts
184
+ model: { provider: "openai", model: "gpt-4o-mini" }
185
+ model: { provider: "anthropic", model: "claude-sonnet-4-20250514" }
186
+ ```
187
+
188
+ The types enforce the difference: `tier` exists only on `nix`, and `model` is
189
+ required on the others. Omitting `model` uses `nix` at the `balanced` tier.
190
+
191
+ A single run can override the provider:
192
+
193
+ ```ts
194
+ await nixet.runs.create(agent.id, { input: "…", provider: "openai" });
195
+ ```
196
+
197
+ ## Built-in tools
198
+
199
+ | Tool | What it does |
200
+ | --- | --- |
201
+ | `current_time` | The current date and time |
202
+ | `calculate` | Arithmetic |
203
+ | `web_search` | Searches the web and returns results |
204
+ | `fetch_url` | Reads a web page as text. Private, loopback and cloud-metadata addresses are refused. Long pages are truncated. |
205
+
206
+ Tools are opt-in per version. Your own tools reach an agent through an
207
+ [MCP server](#mcp-servers-and-tools).
208
+
209
+ ## Runs
210
+
211
+ `runs.create` runs an agent and waits for the result.
212
+
213
+ ```ts
214
+ const run = await nixet.runs.create(agent.id, {
215
+ input: "Summarise our refund policy.",
216
+ version: "v2", // pin a version; default is the published one
217
+ provider: "anthropic", // override the version's provider for this run
218
+ sessionId: "sess_123", // group related runs
219
+ userId: user.id, // who the agent is serving
220
+ variables: { region: "EU" },
221
+ mcpServers: ["broker"], // narrow to a subset of the version's servers
222
+ });
223
+
224
+ run.status; // "completed" | "failed" | …
225
+ run.output; // final text
226
+ run.error; // set when status is "failed"
227
+ run.usage; // token counts
228
+ run.cost_usd; // total cost
229
+ run.latency_ms; // wall-clock duration
230
+ run.variables; // the values this run was given
231
+ ```
232
+
233
+ Read runs back:
234
+
235
+ ```ts
236
+ const same = await nixet.runs.retrieve(run.id);
237
+ const recent = await nixet.runs.list(agent.id, { limit: 20 });
238
+ ```
239
+
240
+ Every run records an ordered event log — model calls, tool calls, knowledge
241
+ lookups, memory recall — which you can read at any time:
242
+
243
+ ```ts
244
+ const events = await nixet.runs.events(run.id);
245
+ const toolCalls = await nixet.runs.events(run.id, { type: "run.tool.started" });
246
+ ```
247
+
248
+ ## Streaming
249
+
250
+ `runs.stream` returns a `RunStream` as soon as the run is accepted. Read it in
251
+ **one** of four ways:
252
+
253
+ ```ts
254
+ const stream = await nixet.runs.stream(agent.id, { input: "Explain gravity" });
255
+
256
+ // 1. Text deltas, for a terminal or a socket
257
+ for await (const chunk of stream.chunks()) process.stdout.write(chunk);
258
+
259
+ // 2. Every event, including tool calls
260
+ for await (const event of stream) console.log(event.type, event.data);
261
+
262
+ // 3. The finished text
263
+ const text = await stream.text();
264
+
265
+ // 4. Handlers — subscribe, then consume with one of the above
266
+ stream.on("run.tool.started", (event) => console.log("calling", event.data));
267
+ stream.on("*", (event) => log(event));
268
+ ```
269
+
270
+ `stream.runId` resolves as soon as the server accepts the run, before it
271
+ finishes:
272
+
273
+ ```ts
274
+ const runId = await stream.runId;
275
+ ```
276
+
277
+ Common events:
278
+
279
+ | Event | Meaning |
280
+ | --- | --- |
281
+ | `run.started` | Execution began |
282
+ | `run.output` | A text delta in `data` |
283
+ | `run.model.started` / `run.model.completed` | A model call |
284
+ | `run.tool.started` / `run.tool.completed` / `run.tool.failed` | A tool call |
285
+ | `run.knowledge.started` / `run.knowledge.completed` | A knowledge search |
286
+ | `run.memory.recall.started` / `run.memory.recall.completed` | Memory recall |
287
+ | `run.completed` / `run.failed` / `run.cancelled` | Terminal |
288
+
289
+ The full list is the `RunEventType` union in [api.md](./api.md#types).
290
+
291
+ ### Recovering a dropped stream
292
+
293
+ Execution continues on the server if the client disconnects, and every event
294
+ carries a `sequence` number. Resume from the last one you saw instead of
295
+ running the agent again:
296
+
297
+ ```ts
298
+ const missed = await nixet.runs.events(runId, { after: lastSequenceSeen });
299
+ const final = await nixet.runs.retrieve(runId);
300
+ ```
301
+
302
+ ## Variables
303
+
304
+ A version can declare `{{placeholders}}` in its instructions, and each run
305
+ fills them. The values a run received are recorded on it, so you can always see
306
+ exactly what prompt an agent was given.
307
+
308
+ ```ts
309
+ await nixet.agents.versions.create(agent.id, {
310
+ instructions: "You help {{customer_name}}. Their plan is {{plan}}.",
311
+ variables: ["customer_name", "plan"],
312
+ });
313
+
314
+ await nixet.runs.create(agent.id, {
315
+ input: "What can I do on my plan?",
316
+ variables: { customer_name: "Sam", plan: "Pro" },
317
+ });
318
+ ```
319
+
320
+ Placeholders must be declared: one used in the instructions but not listed in
321
+ `variables` (or listed but unused) is refused at publish. A run must supply
322
+ every declared variable and nothing else; an unknown key is refused rather than
323
+ ignored, so a run can never inject text into a slot the version did not name.
324
+
325
+ ## Tasks
326
+
327
+ A run must finish inside its HTTP request. A **task** does not: it is queued,
328
+ executed by a worker, retried on failure, and polled for. Use it for long
329
+ research, reports, or batches.
330
+
331
+ ```ts
332
+ const task = await nixet.tasks.create({
333
+ agentId: agent.id,
334
+ input: "Research this company and produce a report.",
335
+ maxAttempts: 3, // default 3
336
+ });
337
+
338
+ const finished = await nixet.tasks.wait(task.id, {
339
+ intervalMs: 2_000, // default 2 s
340
+ timeoutMs: 600_000, // default 10 min
341
+ onUpdate: (t) => console.log(t.status),
342
+ });
343
+
344
+ console.log(finished.output);
345
+ console.log(finished.run_id); // the run holding the trace, events and cost
346
+ ```
347
+
348
+ ```ts
349
+ await nixet.tasks.list({ status: "running", agentId: agent.id });
350
+ await nixet.tasks.cancel(task.id); // queued: stops now; running: stops when its run finishes
351
+ await nixet.tasks.retry(task.id); // a failed or cancelled task, attempts reset
352
+ ```
353
+
354
+ `tasks.wait` throws if the timeout passes; the task itself keeps going and can
355
+ be retrieved later.
356
+
357
+ ## Users
358
+
359
+ A **user** is a person your agent serves — your customer, not a member of your
360
+ Nixet workspace. You identify them with your own `reference`. Memory and
361
+ per-user connections are isolated per user.
362
+
363
+ ```ts
364
+ const user = await nixet.users.create({
365
+ reference: "acme_user_8821", // your ID, unique in the workspace
366
+ email: "sam@example.com",
367
+ name: "Sam",
368
+ metadata: { plan: "pro" },
369
+ });
370
+
371
+ const [found] = (await nixet.users.list({ reference: "acme_user_8821" })).data;
372
+ const same = await nixet.users.retrieve(user.id);
373
+ ```
374
+
375
+ ## Conversations
376
+
377
+ A conversation is a durable thread between an agent and a user. Each message is
378
+ a run, so cost, usage and traces work exactly as for single runs; the
379
+ conversation adds history.
380
+
381
+ ```ts
382
+ const convo = await nixet.conversations.create({
383
+ agentId: agent.id,
384
+ userId: user.id,
385
+ title: "Billing question",
386
+ agentVersion: "v2", // pin, so a long thread cannot change behaviour
387
+ memory: { user: true, conversation: true, agent: false }, // all off by default
388
+ });
389
+
390
+ await nixet.conversations.send(convo.id, { input: "Hi, I'm Sam." });
391
+ const reply = await nixet.conversations.send(convo.id, { input: "What's my name?" });
392
+
393
+ const transcript = await nixet.conversations.messages(convo.id); // oldest first
394
+ await nixet.conversations.list({ agentId: agent.id, userId: user.id });
395
+ ```
396
+
397
+ ## Memory
398
+
399
+ Memory is what an agent retains about a person, an agent, or a thread — a
400
+ preference, a constraint — as opposed to the literal transcript. Every call
401
+ names an agent, and optionally a user and a conversation, so one customer's
402
+ memory is never visible to another.
403
+
404
+ Scopes are `user`, `agent` and `conversation`.
405
+
406
+ ```ts
407
+ await nixet.memory.create({
408
+ scope: "user",
409
+ agentId: agent.id,
410
+ userId: user.id,
411
+ content: "Prefers metric units and short answers.",
412
+ expiresAt: "2027-01-01T00:00:00Z", // optional
413
+ });
414
+
415
+ const relevant = await nixet.memory.search({
416
+ query: "what are their preferences?",
417
+ agentId: agent.id,
418
+ userId: user.id,
419
+ limit: 10,
420
+ });
421
+
422
+ const everything = await nixet.memory.list({ agentId: agent.id, userId: user.id });
423
+
424
+ const target = { agentId: agent.id, userId: user.id };
425
+ await nixet.memory.get(memoryId, target);
426
+ await nixet.memory.update(memoryId, { ...target, content: "Prefers imperial units." });
427
+ await nixet.memory.delete(memoryId, target);
428
+ ```
429
+
430
+ `memory.delete` is how you serve an erasure request for what an agent
431
+ remembers about a person.
432
+
433
+ ## Skills
434
+
435
+ A skill is reusable expertise — instructions plus the tools they need —
436
+ versioned like an agent. Agent versions reference skills as `name` (latest
437
+ published) or `name@v2` (pinned).
438
+
439
+ ```ts
440
+ await nixet.skills.create({
441
+ name: "research/company-lookup",
442
+ instructions: "State the industry and size of any company asked about.",
443
+ tools: ["web_search"],
444
+ });
445
+
446
+ await nixet.skills.versions.create(skillId, { instructions: "…" });
447
+ await nixet.skills.versions.list(skillId);
448
+
449
+ await nixet.agents.versions.create(agent.id, {
450
+ instructions: "You are a sales researcher.",
451
+ skills: ["research/company-lookup@v1"],
452
+ });
453
+ ```
454
+
455
+ ## Knowledge
456
+
457
+ Knowledge lets an agent search your own documents. A **collection** is a named
458
+ index with a fixed chunking rule; **sources** are the documents in it.
459
+
460
+ ```ts
461
+ const collection = await nixet.knowledge.collections.create({
462
+ name: "support-policies",
463
+ chunkStrategy: "markdown", // or "recursive" (default)
464
+ chunkSize: 1000, // 128–8000, default 1000
465
+ chunkOverlap: 200, // 0–2000, default 200
466
+ });
467
+
468
+ const source = await nixet.knowledge.sources.create({
469
+ collection: "support-policies",
470
+ kind: "url", // or "text"
471
+ title: "Refund policy",
472
+ content: "https://example.com/refunds",
473
+ });
474
+
475
+ // Ingestion is asynchronous. Wait for "ready" (or "failed", with `error`).
476
+ let current = source;
477
+ while (current.status !== "ready" && current.status !== "failed") {
478
+ await new Promise((r) => setTimeout(r, 2000));
479
+ current = await nixet.knowledge.sources.retrieve(source.id);
480
+ }
481
+
482
+ await nixet.agents.versions.create(agent.id, {
483
+ instructions: "Answer from the support policies.",
484
+ knowledgeCollections: ["support-policies"],
485
+ });
486
+ ```
487
+
488
+ A version names collections rather than embedding them, so documents added
489
+ later are found without republishing. Collections and sources are not editable:
490
+ to re-chunk, create a new collection; to change a document, delete the source
491
+ and add it again. A collection can only be deleted once it has no sources.
492
+
493
+ To upload a file into a collection, use
494
+ [`documents.convert`](#document-conversion) with `collection`.
495
+
496
+ ## Document conversion
497
+
498
+ Converts a document to Markdown and returns it in the response. Formats include
499
+ PDF, Word (`doc`, `docx`), Excel (`xlsx`), PowerPoint (`ppt`, `pptx`),
500
+ OpenDocument (`odt`, `ods`, `odp`), RTF, EPUB and CSV, detected from the file's
501
+ content rather than its extension. Files up to 20 MB.
502
+
503
+ ```ts
504
+ import { openAsBlob } from "node:fs";
505
+
506
+ const result = await nixet.documents.convert({
507
+ file: await openAsBlob("statement.pdf"),
508
+ password: "secret", // for protected PDFs; used once, never stored
509
+ });
510
+
511
+ result.markdown;
512
+ result.page_count;
513
+ result.ocr_pages; // pages read by OCR, if any
514
+ ```
515
+
516
+ From bytes, pass a filename (it matters for CSV, which has no signature):
517
+
518
+ ```ts
519
+ await nixet.documents.convert({ file: bytes, filename: "data.csv" });
520
+ ```
521
+
522
+ Nothing is stored unless you name a collection, in which case the document is
523
+ also kept as a knowledge source:
524
+
525
+ ```ts
526
+ const { source } = await nixet.documents.convert({
527
+ file: blob,
528
+ collection: "support-policies",
529
+ title: "Refund policy 2026",
530
+ });
531
+ ```
532
+
533
+ A password-protected document cannot be stored in a collection, because the
534
+ password is not kept and nothing could open it again.
535
+
536
+ > Scanned PDFs with no text layer are not supported yet.
537
+
538
+ ## MCP servers and tools
539
+
540
+ Your own tools reach an agent through remote [MCP](https://modelcontextprotocol.io)
541
+ servers (`http` or `sse` transport). Registering a server discovers its tools.
542
+
543
+ ```ts
544
+ await nixet.secrets.create({ name: "github-token", value: process.env.GH_PAT! });
545
+
546
+ const server = await nixet.mcpServers.create({
547
+ name: "github",
548
+ url: "https://mcp.example.com/mcp",
549
+ auth: { type: "bearer", secret: "github-token" },
550
+ });
551
+
552
+ const tools = await nixet.tools.list({ serverName: "github" });
553
+
554
+ await nixet.agents.versions.create(agent.id, {
555
+ instructions: "Use the GitHub tools to answer questions about the repo.",
556
+ mcpServers: ["github"],
557
+ toolPolicies: { "github.delete_repo": "deny" },
558
+ });
559
+ ```
560
+
561
+ Authentication options — all except `none` and `per_user` name a stored
562
+ [secret](#secrets) rather than carrying the credential:
563
+
564
+ ```ts
565
+ auth: { type: "none" }
566
+ auth: { type: "bearer", secret: "github-token" }
567
+ auth: { type: "header", header: "X-Api-Key", secret: "my-key" }
568
+ auth: { type: "oauth", secret: "my-access-token" }
569
+ auth: { type: "per_user", scheme: "api_key" } // see Per-user connections
570
+ ```
571
+
572
+ Each tool carries `tags` (`read`, `write`, `destructive`, `external`) and a
573
+ `default_policy`. Tags come from the server's own annotations or from the tool
574
+ name, and they only decide the default. **What an agent may do is the policy on
575
+ the version**, which you control with `toolPolicies`. The `ask` policy is
576
+ reserved for approvals and is refused at publish for now.
577
+
578
+ Server URLs are checked at registration: private and loopback addresses are
579
+ refused. Changing a server's URL changes what published versions reach without
580
+ republishing them.
581
+
582
+ ```ts
583
+ await nixet.mcpServers.update(server.id, { url: "https://new.example.com/mcp" });
584
+ await nixet.mcpServers.del(server.id);
585
+ ```
586
+
587
+ ## Per-user connections
588
+
589
+ When every end user links their own account on the same server — a broker, a
590
+ CRM — register the server once with `per_user` auth and store one credential
591
+ per user. A run uses the credential of the user it names.
592
+
593
+ ```ts
594
+ await nixet.mcpServers.create({
595
+ name: "broker",
596
+ url: "https://mcp.broker.example.com/mcp",
597
+ auth: { type: "per_user", scheme: "api_key" },
598
+ });
599
+
600
+ await nixet.connections.create({
601
+ userId: user.id,
602
+ server: "broker",
603
+ value: userSuppliedKey,
604
+ expiresAt: "2026-12-01T00:00:00Z", // optional
605
+ refreshValue: refreshToken, // optional
606
+ });
607
+
608
+ await nixet.runs.create(agent.id, { input: "What do I hold?", userId: user.id });
609
+ ```
610
+
611
+ ```ts
612
+ await nixet.connections.list({ userId: user.id, status: "active" });
613
+ await nixet.connections.revoke(connectionId); // erases the credential, keeps the record
614
+ ```
615
+
616
+ Credentials are write-only and never returned. A run that needs a per-user
617
+ server whose connection is missing or expired **fails** rather than calling the
618
+ server unauthenticated. Statuses: `pending`, `active`, `expired`, `revoked`.
619
+
620
+ ## Guardrails
621
+
622
+ Guardrails inspect and rewrite what an agent is given and what it says. They are
623
+ defined once per workspace and named by versions.
624
+
625
+ Three stages:
626
+
627
+ - `input` — before the model sees the text
628
+ - `output` — before the caller sees the response
629
+ - `tool_result` — on what a tool returned. Tool results can reach your
630
+ application without passing through the agent's text, so an `output` guard
631
+ never sees them.
632
+
633
+ Four actions: `allow`, `modify` (rewrite and continue), `warn` (pass through and
634
+ record), `block`.
635
+
636
+ ```ts
637
+ // Pattern guard: find and replace
638
+ await nixet.guardrails.create({
639
+ name: "account-scrub",
640
+ stage: "output",
641
+ action: "modify",
642
+ patterns: [{ match: "\\b\\d{12}\\b", replace: "[ACCOUNT]" }],
643
+ });
644
+
645
+ // Built-in detector
646
+ await nixet.guardrails.create({
647
+ name: "no-competitors",
648
+ stage: "output",
649
+ action: "block",
650
+ detector: "topics", // "pii" | "topics" | "length"
651
+ topics: ["competitor pricing"],
652
+ message: "I can't discuss that.",
653
+ });
654
+
655
+ await nixet.agents.versions.create(agent.id, {
656
+ instructions: "…",
657
+ guardrails: {
658
+ input: ["no-competitors"],
659
+ output: ["account-scrub"],
660
+ tool_result: ["account-scrub"],
661
+ mode: "run_all", // or "fail_fast"
662
+ on_block: "return_message", // or "error"
663
+ },
664
+ });
665
+ ```
666
+
667
+ Guards in one stage run in order, and under `run_all` each sees the text the
668
+ previous one produced, so several `modify` guards compose. Editing a guard's
669
+ rules applies on the next run everywhere it is named. When a version has output
670
+ guards, output events are buffered so a rewritten chunk is never sent first.
671
+
672
+ ```ts
673
+ await nixet.guardrails.list({ stage: "output" });
674
+ await nixet.guardrails.retrieve(guardrailId);
675
+ ```
676
+
677
+ ## Redaction
678
+
679
+ A version can mask personal data in run input and output before it reaches the
680
+ model.
681
+
682
+ ```ts
683
+ await nixet.agents.versions.create(agent.id, {
684
+ instructions: "…",
685
+ redaction: {
686
+ mode: "standard", // "off" | "structured" | "standard" | "strict"
687
+ reversible: true, // restore real values in the reply
688
+ retainFor: "24h", // how long the reversible map is kept
689
+ },
690
+ });
691
+ ```
692
+
693
+ Redaction reduces personal data; it does not guarantee removal, and traces are
694
+ not redacted. It cannot be combined with MCP servers, because tools would
695
+ receive placeholders instead of real values. `run.redaction` reports what was
696
+ masked, as counts.
697
+
698
+ ## Secrets
699
+
700
+ Credentials you give Nixet so an agent can reach something of yours. Values are
701
+ write-only: no method returns one.
702
+
703
+ ```ts
704
+ const secret = await nixet.secrets.create({
705
+ name: "github-token",
706
+ value: process.env.GH_PAT!,
707
+ description: "Read-only PAT",
708
+ });
709
+
710
+ await nixet.secrets.update(secret.id, { value: newToken }); // rotate; picked up on the next run
711
+ await nixet.secrets.list({ name: "github-token" }); // metadata and a hint only
712
+ await nixet.secrets.del(secret.id);
713
+ ```
714
+
715
+ Deleting a secret breaks anything that names it, including published versions.
716
+
717
+ ## Pagination
718
+
719
+ List methods return a page:
720
+
721
+ ```ts
722
+ const page = await nixet.agents.list({ limit: 50, offset: 0 });
723
+ page.data; // this page
724
+ page.count; // total matching, across all pages
725
+ ```
726
+
727
+ Fetch everything:
728
+
729
+ ```ts
730
+ async function all<T>(fetchPage: (offset: number) => Promise<{ data: T[]; count: number }>) {
731
+ const items: T[] = [];
732
+ for (let offset = 0; ; ) {
733
+ const page = await fetchPage(offset);
734
+ items.push(...page.data);
735
+ offset += page.data.length;
736
+ if (page.data.length === 0 || offset >= page.count) return items;
737
+ }
738
+ }
739
+
740
+ const agents = await all((offset) => nixet.agents.list({ limit: 100, offset }));
741
+ ```
742
+
743
+ ## Errors
744
+
745
+ Every failure is a subclass of `NixetError`. API errors carry `status` and
746
+ `requestId` — include the request ID when contacting support.
747
+
748
+ ```ts
749
+ import {
750
+ APIError,
751
+ BadRequestError,
752
+ NotFoundError,
753
+ RateLimitError,
754
+ ConnectionError,
755
+ } from "@nixet/sdk";
756
+
757
+ try {
758
+ await nixet.runs.create(agentId, { input: "…" });
759
+ } catch (error) {
760
+ if (error instanceof NotFoundError) {
761
+ // no such agent in this workspace
762
+ } else if (error instanceof BadRequestError) {
763
+ console.error(error.message); // says what was wrong
764
+ } else if (error instanceof RateLimitError) {
765
+ // already retried; back off
766
+ } else if (error instanceof APIError) {
767
+ console.error(error.status, error.requestId);
768
+ } else if (error instanceof ConnectionError) {
769
+ // network failure, after retries
770
+ }
771
+ }
772
+ ```
773
+
774
+ | Class | Status |
775
+ | --- | --- |
776
+ | `BadRequestError` | 400 |
777
+ | `AuthenticationError` | 401 |
778
+ | `PermissionError` | 403 |
779
+ | `NotFoundError` | 404 |
780
+ | `ConflictError` | 409 |
781
+ | `RateLimitError` | 429 |
782
+ | `ServerError` | 5xx |
783
+ | `APIError` | any other status |
784
+ | `ConnectionError` | the API could not be reached |
785
+
786
+ Resources in another workspace answer 404, not 403, so their IDs are never
787
+ confirmed.
788
+
789
+ ## Retries, timeouts and cancellation
790
+
791
+ Connection failures, `429` and `5xx` responses are retried automatically with
792
+ exponential backoff and jitter (up to 8 seconds between attempts), `maxRetries`
793
+ times. A `4xx` is never retried.
794
+
795
+ ```ts
796
+ const nixet = new Nixet({ maxRetries: 0 }); // disable retries
797
+ ```
798
+
799
+ Every method accepts an `AbortSignal`:
800
+
801
+ ```ts
802
+ const controller = new AbortController();
803
+ setTimeout(() => controller.abort(), 30_000);
804
+
805
+ await nixet.runs.create(agentId, { input: "…" }, { signal: controller.signal });
806
+ ```
807
+
808
+ `documents.convert` takes `signal` inside its params instead.
809
+
810
+ ## TypeScript
811
+
812
+ The SDK is written in TypeScript and ships declarations. Every request and
813
+ response type is exported:
814
+
815
+ ```ts
816
+ import type {
817
+ Agent, AgentVersion, Run, RunEvent, RunEventType,
818
+ CreateAgentParams, CreateRunParams, CreateVersionParams,
819
+ Task, User, Conversation, MemoryRow, KnowledgeSource, McpServer, McpTool,
820
+ } from "@nixet/sdk";
821
+ ```
822
+
823
+ Responses use the API's `snake_case` field names (`run.cost_usd`); request
824
+ parameters use `camelCase` (`{ userId }`).
825
+
826
+ Both ESM and CommonJS are supported:
827
+
828
+ ```ts
829
+ import { Nixet } from "@nixet/sdk"; // ESM
830
+ const { Nixet } = require("@nixet/sdk"); // CommonJS
831
+ ```
832
+
833
+ ## Use with Claude Code and Codex
834
+
835
+ The Nixet plugin teaches your coding agent this SDK, so it looks calls up
836
+ rather than guessing them. It adds skills for building an agent, running one,
837
+ debugging a run, and working with conversations, memory, tasks, MCP tools,
838
+ secrets, skills and knowledge.
839
+
840
+ **Claude Code**
841
+
842
+ ```bash
843
+ claude plugin marketplace add nixetio/nixet-sdk
844
+ claude plugin install nixet@nixet
845
+ ```
846
+
847
+ **Codex**
848
+
849
+ ```bash
850
+ codex plugin marketplace add nixetio/nixet-sdk
851
+ codex plugin install nixet@nixet
852
+ ```
853
+
854
+ Then set `NIXET_API_KEY` and ask, for example, *"Build me a Nixet agent that
855
+ answers support questions."*
856
+
857
+ ## Requirements
858
+
859
+ - Node.js 18 or later, Deno, Bun, or any runtime with `fetch`
860
+ - TypeScript 5.5 or later, if you use TypeScript
861
+
862
+ ## Support
863
+
864
+ - Source and issues: [github.com/nixetio/nixet-sdk](https://github.com/nixetio/nixet-sdk)
865
+ - Website: [nixet.ai](https://nixet.ai)
866
+ - Console: [console.nixet.ai](https://console.nixet.ai)
867
+ - Security issues: see [SECURITY.md](./SECURITY.md)
868
+
869
+ ## License
870
+
871
+ [MIT](./LICENSE)