@gpt-core/client 0.10.13 → 0.10.20
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 +101 -9
- package/dist/index.d.mts +162 -6
- package/dist/index.d.ts +162 -6
- package/dist/index.js +133 -10
- package/dist/index.mjs +131 -10
- package/llms.txt +1 -0
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -159,12 +159,23 @@ const client = new GptClient({
|
|
|
159
159
|
apiKey: 'sk_live_...', // Application API key
|
|
160
160
|
token: 'eyJhbGc...', // User JWT token
|
|
161
161
|
|
|
162
|
+
// API version (optional, uses SDK default if not specified)
|
|
163
|
+
apiVersion: '2025-12-03',
|
|
164
|
+
|
|
165
|
+
// Security configuration (optional)
|
|
166
|
+
security: {
|
|
167
|
+
requireHttps: false, // Throw error on HTTP (default: warn only)
|
|
168
|
+
warnBrowserApiKey: true, // Warn about API keys in browser (default: true)
|
|
169
|
+
},
|
|
170
|
+
|
|
162
171
|
// Retry configuration (optional)
|
|
163
172
|
retry: {
|
|
164
173
|
maxRetries: 3, // Default: 3
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
174
|
+
initialDelay: 1000, // Default: 1000ms (renamed from minTimeout)
|
|
175
|
+
maxDelay: 32000, // Default: 32000ms (renamed from maxTimeout)
|
|
176
|
+
retryableStatusCodes: [429, 500, 502, 503, 504],
|
|
177
|
+
totalTimeout: 300000, // Total timeout across all retries (ms)
|
|
178
|
+
maxRetryAfter: 60, // Max Retry-After header value (seconds)
|
|
168
179
|
},
|
|
169
180
|
|
|
170
181
|
// Disable retries
|
|
@@ -172,6 +183,54 @@ const client = new GptClient({
|
|
|
172
183
|
});
|
|
173
184
|
```
|
|
174
185
|
|
|
186
|
+
## Security Options
|
|
187
|
+
|
|
188
|
+
| Option | Type | Default | Description |
|
|
189
|
+
|--------|------|---------|-------------|
|
|
190
|
+
| `requireHttps` | boolean | `false` | Throw `InsecureConnectionError` on non-HTTPS URLs |
|
|
191
|
+
| `warnBrowserApiKey` | boolean | `true` | Warn when API key detected in browser environment |
|
|
192
|
+
|
|
193
|
+
### HTTPS Enforcement
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
// Development: Warns only
|
|
197
|
+
const devClient = new GptClient({
|
|
198
|
+
baseUrl: 'http://localhost:22222',
|
|
199
|
+
apiKey: process.env.API_KEY,
|
|
200
|
+
security: { requireHttps: false },
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// Production: Blocks HTTP
|
|
204
|
+
const prodClient = new GptClient({
|
|
205
|
+
baseUrl: 'https://api.gpt-core.com',
|
|
206
|
+
apiKey: process.env.API_KEY,
|
|
207
|
+
security: { requireHttps: true },
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
try {
|
|
211
|
+
await prodClient.agents.list();
|
|
212
|
+
} catch (error) {
|
|
213
|
+
if (error instanceof InsecureConnectionError) {
|
|
214
|
+
console.error('Cannot use HTTP in production');
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### API Key Validation
|
|
220
|
+
|
|
221
|
+
The SDK validates API key format and warns about elevated privilege keys:
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
// Valid keys: sk_tenant_*, sk_app_*, sk_srv_*, sk_sys_*
|
|
225
|
+
// sk_sys_* keys trigger warnings (elevated privileges)
|
|
226
|
+
|
|
227
|
+
const client = new GptClient({
|
|
228
|
+
apiKey: 'sk_sys_abc123',
|
|
229
|
+
});
|
|
230
|
+
// [GPT Core SDK] Using system-level API key (sk_sys_).
|
|
231
|
+
// Ensure this is intended for platform operations.
|
|
232
|
+
```
|
|
233
|
+
|
|
175
234
|
## API Reference
|
|
176
235
|
|
|
177
236
|
### Identity
|
|
@@ -336,7 +395,7 @@ try {
|
|
|
336
395
|
|
|
337
396
|
### Pagination
|
|
338
397
|
|
|
339
|
-
Easily iterate over large datasets:
|
|
398
|
+
Easily iterate over large datasets with built-in memory protection:
|
|
340
399
|
|
|
341
400
|
```typescript
|
|
342
401
|
import { paginateAll } from '@gpt-core/client';
|
|
@@ -346,12 +405,23 @@ for await (const workspace of client.platform.workspaces.listAll()) {
|
|
|
346
405
|
console.log(workspace.attributes.name);
|
|
347
406
|
}
|
|
348
407
|
|
|
349
|
-
// With limit
|
|
408
|
+
// With limit (default: 10,000)
|
|
350
409
|
for await (const doc of client.extraction.documents.listAll({ limit: 100 })) {
|
|
351
410
|
console.log(doc.attributes.filename);
|
|
352
411
|
}
|
|
412
|
+
|
|
413
|
+
// Custom page size
|
|
414
|
+
for await (const item of paginateAll(fetcher, { pageSize: 50, limit: 1000 })) {
|
|
415
|
+
// Process items
|
|
416
|
+
}
|
|
353
417
|
```
|
|
354
418
|
|
|
419
|
+
**Pagination Safety:**
|
|
420
|
+
|
|
421
|
+
- **Default Limit**: 10,000 items max (prevents memory exhaustion)
|
|
422
|
+
- **Warning**: Shows warning when fetching > 1,000 items
|
|
423
|
+
- **Configurable**: Set custom `limit` for your use case
|
|
424
|
+
|
|
355
425
|
### Streaming
|
|
356
426
|
|
|
357
427
|
Stream AI responses in real-time:
|
|
@@ -376,16 +446,19 @@ for await (const chunk of streamMessage(response)) {
|
|
|
376
446
|
|
|
377
447
|
### Retry Logic
|
|
378
448
|
|
|
379
|
-
Automatic retries with exponential backoff:
|
|
449
|
+
Automatic retries with exponential backoff and circuit breaker:
|
|
380
450
|
|
|
381
451
|
```typescript
|
|
382
|
-
// Retries are enabled by default
|
|
452
|
+
// Retries are enabled by default with circuit breaker protection
|
|
383
453
|
const client = new GptClient({
|
|
384
454
|
baseUrl: 'https://api.gpt-core.com',
|
|
385
455
|
token: 'token',
|
|
386
456
|
retry: {
|
|
387
|
-
maxRetries: 5,
|
|
388
|
-
|
|
457
|
+
maxRetries: 5, // Retry up to 5 times
|
|
458
|
+
initialDelay: 1000, // Start with 1s delay
|
|
459
|
+
maxDelay: 32000, // Max delay between retries
|
|
460
|
+
totalTimeout: 300000, // Total timeout (5 min) prevents infinite loops
|
|
461
|
+
maxRetryAfter: 60, // Cap Retry-After header to 60s
|
|
389
462
|
},
|
|
390
463
|
});
|
|
391
464
|
|
|
@@ -397,6 +470,25 @@ const noRetryClient = new GptClient({
|
|
|
397
470
|
});
|
|
398
471
|
```
|
|
399
472
|
|
|
473
|
+
**Retry Behavior:**
|
|
474
|
+
|
|
475
|
+
- **Circuit Breaker**: Total timeout prevents unbounded retry loops
|
|
476
|
+
- **Retry-After Validation**: Server Retry-After headers capped at 60 seconds
|
|
477
|
+
- **Jitter**: Random delay added to prevent thundering herd
|
|
478
|
+
- **Protected Status Codes**: 429, 500, 502, 503, 504
|
|
479
|
+
|
|
480
|
+
```typescript
|
|
481
|
+
import { RetryTimeoutError } from '@gpt-core/client';
|
|
482
|
+
|
|
483
|
+
try {
|
|
484
|
+
await client.agents.list();
|
|
485
|
+
} catch (error) {
|
|
486
|
+
if (error instanceof RetryTimeoutError) {
|
|
487
|
+
console.error('Retry timeout exceeded:', error.message);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
```
|
|
491
|
+
|
|
400
492
|
## TypeScript Support
|
|
401
493
|
|
|
402
494
|
The SDK is written in TypeScript and provides full type safety:
|