@gpt-core/client 0.10.21 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +239 -154
- package/dist/index.d.mts +3750 -40715
- package/dist/index.d.ts +3750 -40715
- package/dist/index.js +4280 -4168
- package/dist/index.mjs +4262 -3790
- package/llms.txt +360 -596
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -16,10 +16,11 @@ NOT for: admin operations (use @gpt-core/admin instead).
|
|
|
16
16
|
Quick patterns:
|
|
17
17
|
- Initialize: new GptClient({ baseUrl, apiKey?, token? })
|
|
18
18
|
- Auth: client.identity.login(email, password) -> { user, token }
|
|
19
|
-
- Documents: client.extraction.documents.
|
|
20
|
-
- AI Search: client.ai.search(query,
|
|
21
|
-
- Agents: client.
|
|
19
|
+
- Documents: client.extraction.documents.upload(file)
|
|
20
|
+
- AI Search: client.ai.search(query, options?)
|
|
21
|
+
- Agents: client.agents.list() / .create(name, systemPrompt)
|
|
22
22
|
- Workspaces: client.platform.workspaces.mine()
|
|
23
|
+
- Threads: client.threads.create(title) / .messages.send(threadId, content)
|
|
23
24
|
|
|
24
25
|
All methods return typed responses. Errors throw typed exceptions (AuthenticationError, ValidationError, etc).
|
|
25
26
|
AI_CONTEXT_END -->
|
|
@@ -41,10 +42,11 @@ AI_CONTEXT_END -->
|
|
|
41
42
|
> |------|------|
|
|
42
43
|
> | Login | `await client.identity.login(email, password)` |
|
|
43
44
|
> | List workspaces | `await client.platform.workspaces.mine()` |
|
|
44
|
-
> | Upload document | `await client.extraction.documents.
|
|
45
|
+
> | Upload document | `await client.extraction.documents.upload(file)` |
|
|
45
46
|
> | AI search | `await client.ai.search(query)` |
|
|
46
|
-
> | Create agent | `await client.
|
|
47
|
-
> | Send message | `await client.
|
|
47
|
+
> | Create agent | `await client.agents.create(name, systemPrompt)` |
|
|
48
|
+
> | Send message | `await client.threads.messages.send(threadId, content)` |
|
|
49
|
+
> | Verify webhook | `await new Webhooks(secret).verify(body, signature)` |
|
|
48
50
|
>
|
|
49
51
|
> **See [llms.txt](llms.txt) for complete AI-readable SDK reference.**
|
|
50
52
|
|
|
@@ -52,13 +54,20 @@ AI_CONTEXT_END -->
|
|
|
52
54
|
|
|
53
55
|
## Features
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
- **Fully Typed** - Complete TypeScript support with auto-generated types from OpenAPI specs
|
|
58
|
+
- **Class-Based API** - Stripe-style `GptClient` with namespaced methods (12 namespaces, ~135 curated methods)
|
|
59
|
+
- **Runtime Validation** - Zod schemas for request validation
|
|
60
|
+
- **Smart Error Handling** - Custom error classes with detailed context
|
|
61
|
+
- **Automatic Retries** - Exponential backoff with circuit breaker for transient failures
|
|
62
|
+
- **Idempotency Keys** - Auto-generated for POST/PATCH/DELETE requests
|
|
63
|
+
- **Webhook Verification** - HMAC-SHA256 signature verification with timing-safe comparison
|
|
64
|
+
- **Environment Fallback** - Auto-reads `GPTCORE_BASE_URL`, `GPTCORE_API_KEY`, `GPTCORE_TOKEN`
|
|
65
|
+
- **Browser Safety** - Throws `BrowserApiKeyError` when API keys used in browser without opt-in
|
|
66
|
+
- **Structured Logging** - Configurable log levels and custom logger support
|
|
67
|
+
- **Custom Fetch** - Bring your own fetch implementation for testing or custom network layers
|
|
68
|
+
- **Pagination Support** - Async iterators for easy iteration over large datasets
|
|
69
|
+
- **Streaming Support** - Server-Sent Events (SSE) for real-time AI responses
|
|
70
|
+
- **JSON:API Compliant** - Automatic envelope unwrapping
|
|
62
71
|
|
|
63
72
|
## Installation
|
|
64
73
|
|
|
@@ -78,26 +87,18 @@ import { GptClient } from "@gpt-core/client";
|
|
|
78
87
|
// Initialize client
|
|
79
88
|
const client = new GptClient({
|
|
80
89
|
baseUrl: "https://api.gpt-core.com",
|
|
81
|
-
apiKey: "
|
|
82
|
-
token: "
|
|
90
|
+
apiKey: "sk_app_...", // For machine-to-machine
|
|
91
|
+
token: "eyJhbGc...", // For user-authenticated requests
|
|
83
92
|
});
|
|
84
93
|
|
|
85
94
|
// Authenticate a user
|
|
86
|
-
const
|
|
87
|
-
"user@example.com",
|
|
88
|
-
"password",
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
console.log(`Welcome, ${user.attributes.full_name}!`);
|
|
95
|
+
const result = await client.identity.login("user@example.com", "password");
|
|
92
96
|
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
baseUrl: "https://api.gpt-core.com",
|
|
96
|
-
token: token,
|
|
97
|
-
});
|
|
97
|
+
// Update token for subsequent requests
|
|
98
|
+
client.setToken(result.token);
|
|
98
99
|
|
|
99
100
|
// List workspaces
|
|
100
|
-
const workspaces = await
|
|
101
|
+
const workspaces = await client.platform.workspaces.mine();
|
|
101
102
|
```
|
|
102
103
|
|
|
103
104
|
## API Versioning
|
|
@@ -121,7 +122,7 @@ Pin a specific API version to protect your integration from breaking changes:
|
|
|
121
122
|
```typescript
|
|
122
123
|
const client = new GptClient({
|
|
123
124
|
baseUrl: "https://api.gpt-core.com",
|
|
124
|
-
apiKey: "
|
|
125
|
+
apiKey: "sk_app_...",
|
|
125
126
|
apiVersion: "2025-12-03", // Pin to this version
|
|
126
127
|
});
|
|
127
128
|
```
|
|
@@ -155,68 +156,85 @@ This returns the full list of versions with descriptions and deprecation status.
|
|
|
155
156
|
|
|
156
157
|
```typescript
|
|
157
158
|
const client = new GptClient({
|
|
158
|
-
//
|
|
159
|
+
// API base URL (falls back to GPTCORE_BASE_URL env var)
|
|
159
160
|
baseUrl: "https://api.gpt-core.com",
|
|
160
161
|
|
|
161
|
-
// Authentication (provide one or both)
|
|
162
|
-
apiKey: "
|
|
163
|
-
token: "eyJhbGc...", //
|
|
162
|
+
// Authentication (provide one or both; falls back to env vars)
|
|
163
|
+
apiKey: "sk_app_...", // GPTCORE_API_KEY
|
|
164
|
+
token: "eyJhbGc...", // GPTCORE_TOKEN
|
|
164
165
|
|
|
165
166
|
// API version (optional, uses SDK default if not specified)
|
|
166
167
|
apiVersion: "2025-12-03",
|
|
167
168
|
|
|
168
|
-
//
|
|
169
|
+
// Request timeout in milliseconds (default: no timeout)
|
|
170
|
+
timeout: 30000,
|
|
171
|
+
|
|
172
|
+
// Custom fetch implementation (default: globalThis.fetch)
|
|
173
|
+
fetch: customFetch,
|
|
174
|
+
|
|
175
|
+
// Default headers sent with every request (auth headers not overridden)
|
|
176
|
+
defaultHeaders: { "X-Custom-Header": "value" },
|
|
177
|
+
|
|
178
|
+
// Allow API key usage in browser (default: false, throws BrowserApiKeyError)
|
|
179
|
+
dangerouslyAllowBrowser: false,
|
|
180
|
+
|
|
181
|
+
// Log level (default: 'warn')
|
|
182
|
+
logLevel: "debug", // 'debug' | 'info' | 'warn' | 'error' | 'none'
|
|
183
|
+
|
|
184
|
+
// Custom logger (default: console)
|
|
185
|
+
logger: myLogger,
|
|
186
|
+
|
|
187
|
+
// Application info for User-Agent header (Stripe-style)
|
|
188
|
+
appInfo: { name: "MyApp", version: "1.0.0", url: "https://myapp.com" },
|
|
189
|
+
|
|
190
|
+
// Security configuration
|
|
169
191
|
security: {
|
|
170
|
-
requireHttps: false, // Throw
|
|
171
|
-
warnBrowserApiKey: true, // Warn about API keys in browser (default: true)
|
|
192
|
+
requireHttps: false, // Throw InsecureConnectionError on HTTP (default: warn only)
|
|
172
193
|
},
|
|
173
194
|
|
|
174
|
-
// Retry configuration (
|
|
195
|
+
// Retry configuration (default: 3 retries with exponential backoff)
|
|
175
196
|
retry: {
|
|
176
|
-
maxRetries: 3,
|
|
177
|
-
initialDelay: 1000,
|
|
178
|
-
maxDelay: 32000,
|
|
197
|
+
maxRetries: 3,
|
|
198
|
+
initialDelay: 1000,
|
|
199
|
+
maxDelay: 32000,
|
|
179
200
|
retryableStatusCodes: [429, 500, 502, 503, 504],
|
|
180
|
-
totalTimeout: 300000, // Total timeout across all retries (ms)
|
|
181
|
-
maxRetryAfter: 60, // Max Retry-After header value (seconds)
|
|
182
201
|
},
|
|
183
202
|
|
|
184
203
|
// Disable retries
|
|
185
|
-
retry: false,
|
|
204
|
+
// retry: false,
|
|
186
205
|
});
|
|
187
206
|
```
|
|
188
207
|
|
|
189
|
-
## Security
|
|
190
|
-
|
|
191
|
-
| Option | Type | Default | Description |
|
|
192
|
-
| ------------------- | ------- | ------- | ------------------------------------------------- |
|
|
193
|
-
| `requireHttps` | boolean | `false` | Throw `InsecureConnectionError` on non-HTTPS URLs |
|
|
194
|
-
| `warnBrowserApiKey` | boolean | `true` | Warn when API key detected in browser environment |
|
|
208
|
+
## Security
|
|
195
209
|
|
|
196
210
|
### HTTPS Enforcement
|
|
197
211
|
|
|
198
212
|
```typescript
|
|
199
|
-
// Development: Warns only
|
|
213
|
+
// Development: Warns only (localhost is always allowed)
|
|
200
214
|
const devClient = new GptClient({
|
|
201
215
|
baseUrl: "http://localhost:22222",
|
|
202
|
-
apiKey: process.env.API_KEY,
|
|
203
|
-
security: { requireHttps: false },
|
|
204
216
|
});
|
|
205
217
|
|
|
206
|
-
// Production: Blocks HTTP
|
|
218
|
+
// Production: Blocks HTTP connections
|
|
207
219
|
const prodClient = new GptClient({
|
|
208
220
|
baseUrl: "https://api.gpt-core.com",
|
|
209
|
-
apiKey: process.env.API_KEY,
|
|
210
221
|
security: { requireHttps: true },
|
|
211
222
|
});
|
|
223
|
+
```
|
|
212
224
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
225
|
+
### Browser Safety
|
|
226
|
+
|
|
227
|
+
Using API keys in browser environments is blocked by default to prevent credential exposure:
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
// This throws BrowserApiKeyError in browser:
|
|
231
|
+
const client = new GptClient({ apiKey: "sk_app_..." });
|
|
232
|
+
|
|
233
|
+
// Opt-in if you understand the risks:
|
|
234
|
+
const client = new GptClient({
|
|
235
|
+
apiKey: "sk_app_...",
|
|
236
|
+
dangerouslyAllowBrowser: true,
|
|
237
|
+
});
|
|
220
238
|
```
|
|
221
239
|
|
|
222
240
|
### API Key Validation
|
|
@@ -224,14 +242,8 @@ try {
|
|
|
224
242
|
The SDK validates API key format and warns about elevated privilege keys:
|
|
225
243
|
|
|
226
244
|
```typescript
|
|
227
|
-
// Valid
|
|
245
|
+
// Valid prefixes: sk_tenant_*, sk_app_*, sk_srv_*, sk_sys_*
|
|
228
246
|
// sk_sys_* keys trigger warnings (elevated privileges)
|
|
229
|
-
|
|
230
|
-
const client = new GptClient({
|
|
231
|
-
apiKey: "sk_sys_abc123",
|
|
232
|
-
});
|
|
233
|
-
// [GPT Core SDK] Using system-level API key (sk_sys_).
|
|
234
|
-
// Ensure this is intended for platform operations.
|
|
235
247
|
```
|
|
236
248
|
|
|
237
249
|
## API Reference
|
|
@@ -242,7 +254,8 @@ Manage users, authentication, and API keys.
|
|
|
242
254
|
|
|
243
255
|
```typescript
|
|
244
256
|
// Login
|
|
245
|
-
const
|
|
257
|
+
const result = await client.identity.login(email, password);
|
|
258
|
+
client.setToken(result.token);
|
|
246
259
|
|
|
247
260
|
// Register
|
|
248
261
|
const user = await client.identity.register(
|
|
@@ -261,19 +274,17 @@ const profile = await client.identity.profile();
|
|
|
261
274
|
const keys = await client.identity.apiKeys.list();
|
|
262
275
|
const newKey = await client.identity.apiKeys.create("Production Key");
|
|
263
276
|
await client.identity.apiKeys.allocate("key-id", 1000, "Monthly credits");
|
|
277
|
+
await client.identity.apiKeys.revoke("key-id");
|
|
278
|
+
await client.identity.apiKeys.rotate("key-id");
|
|
264
279
|
```
|
|
265
280
|
|
|
266
281
|
### Platform
|
|
267
282
|
|
|
268
|
-
Manage applications, workspaces, and
|
|
283
|
+
Manage applications, workspaces, tenants, and invitations.
|
|
269
284
|
|
|
270
285
|
```typescript
|
|
271
286
|
// Applications
|
|
272
287
|
const apps = await client.platform.applications.list();
|
|
273
|
-
const app = await client.platform.applications.create({
|
|
274
|
-
name: "My App",
|
|
275
|
-
slug: "my-app",
|
|
276
|
-
});
|
|
277
288
|
const app = await client.platform.applications.getBySlug("my-app");
|
|
278
289
|
|
|
279
290
|
// Workspaces
|
|
@@ -285,63 +296,89 @@ const workspace = await client.platform.workspaces.create(
|
|
|
285
296
|
);
|
|
286
297
|
|
|
287
298
|
// Invitations
|
|
288
|
-
await client.platform.invitations.
|
|
299
|
+
await client.platform.invitations.create(
|
|
289
300
|
"colleague@example.com",
|
|
290
301
|
"editor",
|
|
291
302
|
"workspace",
|
|
292
303
|
"workspace-id",
|
|
293
304
|
);
|
|
305
|
+
await client.platform.invitations.accept("invitation-id");
|
|
294
306
|
```
|
|
295
307
|
|
|
296
|
-
###
|
|
308
|
+
### Agents
|
|
297
309
|
|
|
298
|
-
|
|
310
|
+
Create and manage AI agents.
|
|
299
311
|
|
|
300
312
|
```typescript
|
|
301
|
-
//
|
|
302
|
-
const agents = await client.
|
|
303
|
-
const agent = await client.
|
|
313
|
+
// CRUD
|
|
314
|
+
const agents = await client.agents.list();
|
|
315
|
+
const agent = await client.agents.create(
|
|
304
316
|
"Support Agent",
|
|
305
|
-
"You are a helpful
|
|
317
|
+
"You are a helpful assistant",
|
|
306
318
|
);
|
|
319
|
+
const result = await client.agents.test("agent-id", "Hello!");
|
|
320
|
+
await client.agents.clone("agent-id");
|
|
321
|
+
|
|
322
|
+
// Versioning
|
|
323
|
+
const versions = await client.agents.versions.list("agent-id");
|
|
324
|
+
await client.agents.versions.publish("agent-id");
|
|
325
|
+
await client.agents.versions.restore("agent-id", "version-id");
|
|
326
|
+
|
|
327
|
+
// Training
|
|
328
|
+
const examples = await client.agents.training.examples("agent-id");
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### AI
|
|
307
332
|
|
|
308
|
-
|
|
309
|
-
const threads = await client.ai.threads.list();
|
|
310
|
-
const thread = await client.ai.threads.create("Bug Report Discussion");
|
|
311
|
-
const message = await client.ai.threads.sendMessage(thread.id, "Hello AI!");
|
|
333
|
+
Semantic search, embeddings, and conversations.
|
|
312
334
|
|
|
335
|
+
```typescript
|
|
313
336
|
// Search
|
|
314
|
-
const results = await client.ai.search("quarterly earnings"
|
|
337
|
+
const results = await client.ai.search("quarterly earnings");
|
|
338
|
+
const advanced = await client.ai.searchAdvanced("revenue data", { limit: 20 });
|
|
315
339
|
|
|
316
340
|
// Embeddings
|
|
317
341
|
const embedding = await client.ai.embed("text to embed");
|
|
342
|
+
|
|
343
|
+
// Conversations
|
|
344
|
+
const conversations = await client.ai.conversations.list();
|
|
345
|
+
const conv = await client.ai.conversations.create({ title: "New Chat" });
|
|
318
346
|
```
|
|
319
347
|
|
|
320
|
-
###
|
|
348
|
+
### Threads
|
|
321
349
|
|
|
322
|
-
|
|
350
|
+
Real-time messaging threads.
|
|
323
351
|
|
|
324
352
|
```typescript
|
|
325
|
-
//
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
353
|
+
// Threads
|
|
354
|
+
const threads = await client.threads.list();
|
|
355
|
+
const thread = await client.threads.create("Bug Discussion");
|
|
356
|
+
|
|
357
|
+
// Messages
|
|
358
|
+
const messages = await client.threads.messages.list(thread.id);
|
|
359
|
+
await client.threads.messages.send(thread.id, "Hello!");
|
|
360
|
+
|
|
361
|
+
// Actions
|
|
362
|
+
await client.threads.archive(thread.id);
|
|
363
|
+
await client.threads.fork(thread.id);
|
|
364
|
+
await client.threads.export(thread.id);
|
|
365
|
+
```
|
|
333
366
|
|
|
334
|
-
|
|
335
|
-
await client.extraction.documents.analyze(doc.id);
|
|
367
|
+
### Extraction
|
|
336
368
|
|
|
337
|
-
|
|
338
|
-
const doc = await client.extraction.documents.get("doc-id");
|
|
369
|
+
Upload and process documents.
|
|
339
370
|
|
|
340
|
-
|
|
341
|
-
|
|
371
|
+
```typescript
|
|
372
|
+
// Upload
|
|
373
|
+
const doc = await client.extraction.documents.upload(file);
|
|
374
|
+
const status = await client.extraction.documents.status(doc.id);
|
|
342
375
|
|
|
343
376
|
// Results
|
|
344
377
|
const results = await client.extraction.results.list();
|
|
378
|
+
const docResults = await client.extraction.results.byDocument(doc.id);
|
|
379
|
+
|
|
380
|
+
// Batches
|
|
381
|
+
const batch = await client.extraction.batches.create({ name: "Q4 Reports" });
|
|
345
382
|
```
|
|
346
383
|
|
|
347
384
|
### Storage
|
|
@@ -351,19 +388,16 @@ Manage buckets and files.
|
|
|
351
388
|
```typescript
|
|
352
389
|
// Buckets
|
|
353
390
|
const buckets = await client.storage.buckets.list();
|
|
354
|
-
const bucket = await client.storage.buckets.create("uploads",
|
|
391
|
+
const bucket = await client.storage.buckets.create("uploads", "private");
|
|
355
392
|
|
|
356
393
|
// Presigned URLs
|
|
357
|
-
const uploadUrl = await client.storage.
|
|
358
|
-
|
|
359
|
-
"image/png",
|
|
360
|
-
);
|
|
361
|
-
const downloadUrl = await client.storage.presigned.download("file-id");
|
|
394
|
+
const uploadUrl = await client.storage.signUpload("image.png", "image/png");
|
|
395
|
+
const downloadUrl = await client.storage.signDownload("object-id");
|
|
362
396
|
```
|
|
363
397
|
|
|
364
398
|
### Billing
|
|
365
399
|
|
|
366
|
-
Access wallet and
|
|
400
|
+
Access wallet, plans, and payment methods.
|
|
367
401
|
|
|
368
402
|
```typescript
|
|
369
403
|
// Wallet
|
|
@@ -371,8 +405,86 @@ const wallet = await client.billing.wallet.get();
|
|
|
371
405
|
|
|
372
406
|
// Plans
|
|
373
407
|
const plans = await client.billing.plans.list();
|
|
408
|
+
|
|
409
|
+
// Payment Methods
|
|
410
|
+
const methods = await client.billing.paymentMethods.list();
|
|
411
|
+
await client.billing.paymentMethods.setDefault("method-id");
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### Webhooks
|
|
415
|
+
|
|
416
|
+
Manage webhook configurations and deliveries.
|
|
417
|
+
|
|
418
|
+
```typescript
|
|
419
|
+
// Configs
|
|
420
|
+
const configs = await client.webhooks.configs.list();
|
|
421
|
+
await client.webhooks.configs.create("https://myapp.com/webhooks", [
|
|
422
|
+
"document.processed",
|
|
423
|
+
]);
|
|
424
|
+
await client.webhooks.configs.test("config-id");
|
|
425
|
+
await client.webhooks.configs.rotateSecret("config-id");
|
|
426
|
+
|
|
427
|
+
// Deliveries
|
|
428
|
+
const deliveries = await client.webhooks.deliveries.list();
|
|
429
|
+
await client.webhooks.deliveries.retry("delivery-id");
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
### Search
|
|
433
|
+
|
|
434
|
+
Full-text and semantic search.
|
|
435
|
+
|
|
436
|
+
```typescript
|
|
437
|
+
const results = await client.search.query("invoice");
|
|
438
|
+
const semantic = await client.search.semantic("similar to this document");
|
|
439
|
+
const suggestions = await client.search.suggest("inv");
|
|
440
|
+
|
|
441
|
+
// Saved searches
|
|
442
|
+
const saved = await client.search.saved.list();
|
|
443
|
+
await client.search.saved.run("saved-search-id");
|
|
374
444
|
```
|
|
375
445
|
|
|
446
|
+
### Communication
|
|
447
|
+
|
|
448
|
+
Notification management.
|
|
449
|
+
|
|
450
|
+
```typescript
|
|
451
|
+
// Logs
|
|
452
|
+
const logs = await client.communication.notifications.logs();
|
|
453
|
+
|
|
454
|
+
// Methods
|
|
455
|
+
const methods = await client.communication.notifications.methods.list();
|
|
456
|
+
await client.communication.notifications.methods.verify("method-id");
|
|
457
|
+
|
|
458
|
+
// Preferences
|
|
459
|
+
const prefs = await client.communication.notifications.preferences.list();
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
## Webhook Signature Verification
|
|
463
|
+
|
|
464
|
+
Verify incoming webhook payloads using HMAC-SHA256 signatures:
|
|
465
|
+
|
|
466
|
+
```typescript
|
|
467
|
+
import { Webhooks } from "@gpt-core/client";
|
|
468
|
+
|
|
469
|
+
const wh = new Webhooks("whsec_your_secret_here");
|
|
470
|
+
|
|
471
|
+
// In your webhook handler (Express example):
|
|
472
|
+
app.post("/webhooks", async (req, res) => {
|
|
473
|
+
const signature = req.headers["x-gptcore-signature"];
|
|
474
|
+
const body = req.body; // raw string body
|
|
475
|
+
|
|
476
|
+
try {
|
|
477
|
+
await wh.verify(body, signature);
|
|
478
|
+
// Process the webhook...
|
|
479
|
+
res.status(200).send("OK");
|
|
480
|
+
} catch (err) {
|
|
481
|
+
res.status(400).send("Invalid signature");
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
The `whsec_` prefix on secrets is stripped automatically. Signatures are checked with timing-safe comparison and a default 5-minute tolerance for timestamp freshness.
|
|
487
|
+
|
|
376
488
|
## Advanced Features
|
|
377
489
|
|
|
378
490
|
### Error Handling
|
|
@@ -410,17 +522,7 @@ Easily iterate over large datasets with built-in memory protection:
|
|
|
410
522
|
```typescript
|
|
411
523
|
import { paginateAll } from "@gpt-core/client";
|
|
412
524
|
|
|
413
|
-
// Using async iteration
|
|
414
|
-
for await (const workspace of client.platform.workspaces.listAll()) {
|
|
415
|
-
console.log(workspace.attributes.name);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
525
|
// With limit (default: 10,000)
|
|
419
|
-
for await (const doc of client.extraction.documents.listAll({ limit: 100 })) {
|
|
420
|
-
console.log(doc.attributes.filename);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// Custom page size
|
|
424
526
|
for await (const item of paginateAll(fetcher, { pageSize: 50, limit: 1000 })) {
|
|
425
527
|
// Process items
|
|
426
528
|
}
|
|
@@ -439,17 +541,15 @@ Stream AI responses in real-time:
|
|
|
439
541
|
```typescript
|
|
440
542
|
import { streamMessage } from "@gpt-core/client";
|
|
441
543
|
|
|
442
|
-
// Make streaming request
|
|
443
544
|
const response = await fetch(streamingEndpoint, {
|
|
444
545
|
method: "POST",
|
|
445
546
|
headers: { Accept: "text/event-stream" },
|
|
446
547
|
body: JSON.stringify({ content: "Hello AI" }),
|
|
447
548
|
});
|
|
448
549
|
|
|
449
|
-
// Stream the response
|
|
450
550
|
for await (const chunk of streamMessage(response)) {
|
|
451
551
|
if (chunk.type === "content") {
|
|
452
|
-
process.stdout.write(chunk.content);
|
|
552
|
+
process.stdout.write(chunk.content);
|
|
453
553
|
}
|
|
454
554
|
}
|
|
455
555
|
```
|
|
@@ -459,44 +559,30 @@ for await (const chunk of streamMessage(response)) {
|
|
|
459
559
|
Automatic retries with exponential backoff and circuit breaker:
|
|
460
560
|
|
|
461
561
|
```typescript
|
|
462
|
-
// Retries are enabled by default with circuit breaker protection
|
|
463
562
|
const client = new GptClient({
|
|
464
563
|
baseUrl: "https://api.gpt-core.com",
|
|
465
564
|
token: "token",
|
|
466
565
|
retry: {
|
|
467
|
-
maxRetries: 5,
|
|
468
|
-
initialDelay: 1000,
|
|
469
|
-
maxDelay: 32000,
|
|
470
|
-
totalTimeout: 300000, // Total timeout (5 min) prevents infinite loops
|
|
471
|
-
maxRetryAfter: 60, // Cap Retry-After header to 60s
|
|
566
|
+
maxRetries: 5,
|
|
567
|
+
initialDelay: 1000,
|
|
568
|
+
maxDelay: 32000,
|
|
472
569
|
},
|
|
473
570
|
});
|
|
474
571
|
|
|
475
|
-
// Disable retries
|
|
572
|
+
// Disable retries
|
|
476
573
|
const noRetryClient = new GptClient({
|
|
477
|
-
baseUrl: "https://api.gpt-core.com",
|
|
478
|
-
token: "token",
|
|
479
574
|
retry: false,
|
|
480
575
|
});
|
|
481
576
|
```
|
|
482
577
|
|
|
483
|
-
|
|
578
|
+
### Raw Functions
|
|
484
579
|
|
|
485
|
-
|
|
486
|
-
- **Retry-After Validation**: Server Retry-After headers capped at 60 seconds
|
|
487
|
-
- **Jitter**: Random delay added to prevent thundering herd
|
|
488
|
-
- **Protected Status Codes**: 429, 500, 502, 503, 504
|
|
580
|
+
All 403+ generated functions remain available as named exports for power users:
|
|
489
581
|
|
|
490
582
|
```typescript
|
|
491
|
-
import {
|
|
583
|
+
import { getAgents, postUsersAuthLogin } from "@gpt-core/client";
|
|
492
584
|
|
|
493
|
-
|
|
494
|
-
await client.agents.list();
|
|
495
|
-
} catch (error) {
|
|
496
|
-
if (error instanceof RetryTimeoutError) {
|
|
497
|
-
console.error("Retry timeout exceeded:", error.message);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
585
|
+
const { data, error } = await getAgents({ client: myClientInstance });
|
|
500
586
|
```
|
|
501
587
|
|
|
502
588
|
## TypeScript Support
|
|
@@ -504,21 +590,20 @@ try {
|
|
|
504
590
|
The SDK is written in TypeScript and provides full type safety:
|
|
505
591
|
|
|
506
592
|
```typescript
|
|
507
|
-
import type {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
593
|
+
import type {
|
|
594
|
+
BaseClientConfig,
|
|
595
|
+
AppInfo,
|
|
596
|
+
Logger,
|
|
597
|
+
LogLevel,
|
|
598
|
+
RequestOptions,
|
|
599
|
+
} from "@gpt-core/client";
|
|
514
600
|
```
|
|
515
601
|
|
|
516
602
|
## License
|
|
517
603
|
|
|
518
|
-
MIT
|
|
604
|
+
MIT
|
|
519
605
|
|
|
520
606
|
## Support
|
|
521
607
|
|
|
522
|
-
-
|
|
523
|
-
-
|
|
524
|
-
- 🐛 Issues: https://github.com/GPT-Integrators/gpt-core-sdks/issues
|
|
608
|
+
- Documentation: https://docs.gpt-core.com
|
|
609
|
+
- Issues: https://github.com/GPT-Integrators/gpt-core-sdks/issues
|