@puku-ai/sdk 1.0.0 → 2.0.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.
Files changed (2) hide show
  1. package/README.md +23 -129
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,28 +1,29 @@
1
1
  # @puku-ai/sdk
2
2
 
3
- Drop-in replacement for [`@anthropic-ai/sdk`](https://www.npmjs.com/package/@anthropic-ai/sdk)
4
- that routes every request through the **Puku AI gateway**.
3
+ Official TypeScript SDK for the **Puku AI** gateway. One small client class,
4
+ one streaming primitive, and a familiar typed namespace.
5
5
 
6
6
  ```ts
7
7
  import PukuAI from "@puku-ai/sdk";
8
8
 
9
- const client = new PukuAI();
9
+ const client = new PukuAI({
10
+ apiKey: process.env.PUKU_API_KEY!,
11
+ baseURL: process.env.PUKU_BASE_URL!,
12
+ });
13
+
10
14
  const msg = await client.messages.create({
11
- model: "claude-sonnet-4-5",
15
+ model: "puku-ai-2.8",
12
16
  max_tokens: 1024,
13
17
  messages: [{ role: "user", content: "Hello!" }],
14
18
  });
15
19
  console.log(msg.content[0].text);
16
20
  ```
17
21
 
18
- The client class is renamed to **`PukuAI`** (was `Anthropic`) every method,
19
- type, stream primitive, and error class is otherwise identical to
20
- `@anthropic-ai/sdk` 0.81.x. Source code written against the official SDK works
21
- after a two-line change: import path + class name.
22
+ The client class is `PukuAI`. Method names, request shapes, stream events,
23
+ and error classes follow the Anthropic Messages API conventions.
22
24
 
23
25
  ## Contents
24
26
 
25
- - [Why](#why)
26
27
  - [Install](#install)
27
28
  - [Configuration](#configuration)
28
29
  - [Usage](#usage)
@@ -30,18 +31,8 @@ after a two-line change: import path + class name.
30
31
  - [Examples](#examples)
31
32
  - [Documentation](#documentation)
32
33
  - [Namespace](#namespace)
33
- - [How it differs from `@anthropic-ai/sdk`](#how-it-differs-from-anthropic-ai-sdk)
34
34
  - [License](#license)
35
35
 
36
- ## Why
37
-
38
- Puku CLI is a coding assistant built on top of the Anthropic SDK. We want to:
39
-
40
- 1. Route all requests through the Puku AI router so we can pick the best
41
- upstream model per request (Opus / Sonnet / GLM / Kimi / OpenAI-compatible…).
42
- 2. Keep puku-cli's source untouched.
43
- 3. Maintain a single, minimal surface.
44
-
45
36
  ## Install
46
37
 
47
38
  ```bash
@@ -50,39 +41,23 @@ npm install @puku-ai/sdk
50
41
  pnpm add @puku-ai/sdk
51
42
  ```
52
43
 
44
+ > The package is published under the **`puku-ai`** npm org with restricted
45
+ > (private) access. You must be a member of the org on npm to install it.
46
+
53
47
  ## Configuration
54
48
 
55
- > The SDK only reads two environment variables: `PUKU_API_KEY` and
56
- > `PUKU_BASE_URL`. There is no bearer-token path and no fallback to
57
- > `ANTHROPIC_*` env vars. To talk to staging, set
58
- > `PUKU_BASE_URL=https://api-dev.puku.sh`; for prod, set
59
- > `PUKU_BASE_URL=https://api-cli.puku.sh`. See `.env.staging.example` and
60
- > `docs/API-KEY-PLAN.md` § "End-to-end migration order".
49
+ Two environment variables, both required:
50
+
51
+ | Env var | Purpose |
52
+ | --------------- | -------------------------------------- |
53
+ | `PUKU_API_KEY` | Puku API key (sent as `X-Api-Key`) |
54
+ | `PUKU_BASE_URL` | Gateway URL
61
55
 
62
- | Env var | Purpose | Default |
63
- | --------------- | ------------------------ | ------------- |
64
- | `PUKU_API_KEY` | Puku API key | _(required)_ |
65
- | `PUKU_BASE_URL` | Puku AI routing endpoint | _(required)_ |
66
- | `ANTHROPIC_LOG` | Log level (`debug`, `info`, `warn`, `error`) | `warn` |
67
56
 
68
- ### Using an API key
69
57
 
70
- In staging, mint a key via the admin UI (`/account/agents` or
71
- `/account/user-keys`). Keys minted in staging are prefixed `pk_staging_…`.
72
- Copy the plaintext once — it is not recoverable later.
73
58
 
74
- ```bash
75
- # .env.staging
76
- PUKU_BASE_URL=https://api-dev.puku.sh
77
- PUKU_API_KEY=pk_staging_…
78
- ```
79
59
 
80
- ```bash
81
- node --env-file=.env.staging examples/17-agent-key.mjs
82
- ```
83
60
 
84
- The SDK sends `X-Api-Key: pk_staging_…` on every request. No
85
- `Authorization` header — there is no bearer-token path.
86
61
 
87
62
  ## Usage
88
63
 
@@ -94,7 +69,7 @@ import PukuAI from "@puku-ai/sdk";
94
69
  const client = new PukuAI();
95
70
 
96
71
  const msg = await client.messages.create({
97
- model: "claude-sonnet-4-5",
72
+ model: "puku-ai-2.8",
98
73
  max_tokens: 1024,
99
74
  messages: [{ role: "user", content: "Hello!" }],
100
75
  });
@@ -105,7 +80,7 @@ console.log(msg.content[0].text);
105
80
 
106
81
  ```ts
107
82
  const stream = client.messages.stream({
108
- model: "claude-sonnet-4-5",
83
+ model: "puku-ai-2.8",
109
84
  max_tokens: 1024,
110
85
  messages: [{ role: "user", content: "Hello!" }],
111
86
  });
@@ -137,68 +112,11 @@ try {
137
112
  }
138
113
  ```
139
114
 
140
- See [docs/ERROR-HANDLING.md](./docs/ERROR-HANDLING.md) for the full hierarchy.
141
-
142
- ## Feature matrix
143
-
144
- Every API surface in `@anthropic-ai/sdk` 0.81.x is reachable through
145
- `@puku-ai/sdk`. The matrix below shows where each lives.
146
-
147
- | Feature | Call site | Example |
148
- |----------------------------------------|------------------------------------|---------|
149
- | Blocking chat | `client.messages.create(...)` | [01](./examples/01-basic-chat.mjs) |
150
- | Streaming chat | `client.messages.stream(...)` | [02](./examples/02-streaming.mjs) |
151
- | System prompt + prefilling | `system`, last message = assistant | [03](./examples/03-system-prompt.mjs) |
152
- | Multi-turn history | append to `messages` | [04](./examples/04-multi-turn.mjs) |
153
- | Prompt caching | `cache_control: { type: "ephemeral" }` | [05](./examples/05-prompt-caching.mjs) |
154
- | Tool use | `tools: [...]` + manual loop | [06](./examples/06-tool-use.mjs) |
155
- | Vision (base64 / URL / file) | `image` content blocks | [07](./examples/07-vision.mjs) |
156
- | Error handling + aborts | `instanceof PukuAI.*Error` | [08](./examples/08-error-handling.mjs) |
157
- | Async message batches | `client.messages.batches.*` | [09](./examples/09-batches.mjs) |
158
- | MCP servers (beta) | `mcp_servers: [...]` | [10](./examples/10-mcp.mjs) |
159
- | Skills & versions (beta) | `client.beta.skills.*` | [11](./examples/11-skills.mjs) |
160
- | Structured (JSON-schema) output | `output_format: { type: "json_schema", schema }` | [12](./examples/12-structured-output.mjs) |
161
- | Custom client options | `new PukuAI({ ... })` | [14](./examples/14-custom-client-options.mjs) |
162
- | Mocking / local server | `baseURL` + custom `fetch` | [15](./examples/15-testing.mjs) |
163
-
164
- ## Examples
165
-
166
- 15 runnable scripts under [`examples/`](./examples/README.md) cover every
167
- common use case. Quick start:
168
-
169
- ```bash
170
- PUKU_API_KEY=sk-... node examples/01-basic-chat.mjs
171
- ```
172
-
173
- ## Test scripts
174
-
175
- ```bash
176
- # Offline smoke test (24 cases, no API key, mock server on localhost)
177
- bun run smoke
178
-
179
- # Live integration test (14 cases, hits real Puku AI gateway)
180
- # Requires PUKU_API_KEY and PUKU_BASE_URL.
181
- bun run integration
182
-
183
- # Type-level parity check (verifies the full PukuAI.* namespace compiles)
184
- bun run type-check
185
- ```
186
115
 
187
- ## Documentation
188
116
 
189
- Guides under [`docs/`](./docs/README.md):
190
-
191
- - [MIGRATION.md](./docs/MIGRATION.md) — switch from `@anthropic-ai/sdk` in three lines.
192
- - [ERROR-HANDLING.md](./docs/ERROR-HANDLING.md) — error hierarchy & retries.
193
- - [ROUTING.md](./docs/ROUTING.md) — how the Puku AI gateway picks models.
194
- - [TYPES.md](./docs/TYPES.md) — namespace & type reference.
195
117
 
196
118
  ## Namespace
197
119
 
198
- The upstream SDK exposes its types under an `Anthropic` namespace
199
- (`Anthropic.Messages.Message`, etc.); `@puku-ai/sdk` re-exposes the same
200
- namespace under the `PukuAI` name:
201
-
202
120
  ```ts
203
121
  import PukuAI from "@puku-ai/sdk";
204
122
 
@@ -208,7 +126,7 @@ type Beta = PukuAI.Beta.Messages.BetaMessage;
208
126
  type Skill = PukuAI.Beta.Skills.SkillRetrieveResponse;
209
127
  ```
210
128
 
211
- Static helpers that were on `Anthropic.X` are on `PukuAI.X`:
129
+ Static helpers live on the `PukuAI` class:
212
130
 
213
131
  ```ts
214
132
  PukuAI.HUMAN_PROMPT; // "\n\nHuman:"
@@ -222,30 +140,6 @@ PukuAI.APIError; // error class (static)
222
140
  PukuAI.RateLimitError; // error class (static)
223
141
  ```
224
142
 
225
- The original `Anthropic` symbol is also exported as a name alias — both
226
- `new PukuAI()` and `new Anthropic()` return the same class.
227
-
228
- ## How it differs from `@anthropic-ai/sdk`
229
-
230
- The public API is intentionally close to `@anthropic-ai/sdk` — same method
231
- names, same TypeScript types (under `PukuAI.*`). The behavioral differences are:
232
-
233
- 1. The client class is named `PukuAI` (was `Anthropic`).
234
- 2. Every request is forwarded to the Puku AI gateway (`PUKU_BASE_URL`)
235
- instead of directly to `api.anthropic.com`.
236
- 3. **API-key only.** The SDK no longer supports the upstream `authToken` /
237
- `Authorization: Bearer` flow or the `ANTHROPIC_API_KEY` / `ANTHROPIC_BASE_URL`
238
- fallback env vars. Authentication is `PUKU_API_KEY` (sent as `X-Api-Key`).
239
- 4. **Explicit `baseURL` is required.** There is no hardcoded default; the SDK
240
- throws at construction if `baseURL` isn't passed or `PUKU_BASE_URL` isn't set.
241
-
242
- Puku's router picks which upstream model to use per request, then returns a
243
- response in the standard Anthropic format. To bypass Puku (e.g. for A/B
244
- testing), point `PUKU_BASE_URL` at `https://api.anthropic.com`.
245
-
246
- If a feature of `@anthropic-ai/sdk` is missing from `@puku-ai/sdk`, please
247
- [open an issue](https://github.com/puku-sh/puku-ai-sdk/issues).
248
-
249
143
  ## License
250
144
 
251
- MIT
145
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@puku-ai/sdk",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "PukuAI SDK — drop-in replacement for @anthropic-ai/sdk that routes requests through the Puku AI gateway.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",