@nixet/sdk 0.1.0 → 0.1.2

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