@gpt-platform/client 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.
- package/README.md +609 -0
- package/dist/index.d.mts +11370 -0
- package/dist/index.d.ts +11370 -0
- package/dist/index.js +10437 -0
- package/dist/index.mjs +10290 -0
- package/llms.txt +981 -0
- package/package.json +89 -0
package/README.md
ADDED
|
@@ -0,0 +1,609 @@
|
|
|
1
|
+
# @gpt-platform client
|
|
2
|
+
|
|
3
|
+
The official TypeScript SDK for the GPT Core Platform - document extraction, AI agents, and workspace management.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@gpt-platform client)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
<!-- AI_CONTEXT_START
|
|
12
|
+
This SDK provides TypeScript bindings for the GPT Core API.
|
|
13
|
+
Use this for: document extraction, AI agents, workspace management, user authentication.
|
|
14
|
+
NOT for: admin operations (use @gpt-core/admin instead).
|
|
15
|
+
|
|
16
|
+
Quick patterns:
|
|
17
|
+
- Initialize: new GptClient({ baseUrl, apiKey?, token? })
|
|
18
|
+
- Auth: client.identity.login(email, password) -> { user, token }
|
|
19
|
+
- Documents: client.extraction.documents.upload(file)
|
|
20
|
+
- AI Search: client.ai.search(query, options?)
|
|
21
|
+
- Agents: client.agents.list() / .create(name, systemPrompt)
|
|
22
|
+
- Workspaces: client.platform.workspaces.mine()
|
|
23
|
+
- Threads: client.threads.create(title) / .messages.send(threadId, content)
|
|
24
|
+
|
|
25
|
+
All methods return typed responses. Errors throw typed exceptions (AuthenticationError, ValidationError, etc).
|
|
26
|
+
AI_CONTEXT_END -->
|
|
27
|
+
|
|
28
|
+
## For AI Coding Assistants
|
|
29
|
+
|
|
30
|
+
> **TL;DR for Claude, Cursor, Copilot, and other AI assistants:**
|
|
31
|
+
>
|
|
32
|
+
> ```typescript
|
|
33
|
+
> import { GptClient } from "@gpt-platform client";
|
|
34
|
+
> const client = new GptClient({
|
|
35
|
+
> baseUrl: "https://api.example.com",
|
|
36
|
+
> token: "jwt",
|
|
37
|
+
> });
|
|
38
|
+
> ```
|
|
39
|
+
>
|
|
40
|
+
> **Common operations:**
|
|
41
|
+
> | Task | Code |
|
|
42
|
+
> |------|------|
|
|
43
|
+
> | Login | `await client.identity.login(email, password)` |
|
|
44
|
+
> | List workspaces | `await client.platform.workspaces.mine()` |
|
|
45
|
+
> | Upload document | `await client.extraction.documents.upload(file)` |
|
|
46
|
+
> | AI search | `await client.ai.search(query)` |
|
|
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)` |
|
|
50
|
+
>
|
|
51
|
+
> **See [llms.txt](llms.txt) for complete AI-readable SDK reference.**
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
|
|
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
|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npm install @gpt-platform client
|
|
76
|
+
# or
|
|
77
|
+
yarn add @gpt-platform client
|
|
78
|
+
# or
|
|
79
|
+
pnpm add @gpt-platform client
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Quick Start
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { GptClient } from "@gpt-platform client";
|
|
86
|
+
|
|
87
|
+
// Initialize client
|
|
88
|
+
const client = new GptClient({
|
|
89
|
+
baseUrl: "https://api.gpt-core.com",
|
|
90
|
+
apiKey: "sk_app_...", // For machine-to-machine
|
|
91
|
+
token: "eyJhbGc...", // For user-authenticated requests
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Authenticate a user
|
|
95
|
+
const result = await client.identity.login("user@example.com", "password");
|
|
96
|
+
|
|
97
|
+
// Update token for subsequent requests
|
|
98
|
+
client.setToken(result.token);
|
|
99
|
+
|
|
100
|
+
// List workspaces
|
|
101
|
+
const workspaces = await client.platform.workspaces.mine();
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## API Versioning
|
|
105
|
+
|
|
106
|
+
The SDK uses Stripe-style API versioning. A default API version is sent with every request via the `Accept` header.
|
|
107
|
+
|
|
108
|
+
### Default Behavior
|
|
109
|
+
|
|
110
|
+
Every request automatically includes the SDK's built-in API version:
|
|
111
|
+
|
|
112
|
+
```http
|
|
113
|
+
Accept: application/vnd.api+json; version=2025-12-03
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
No configuration is needed -- the SDK sends `DEFAULT_API_VERSION` from `base-client.ts` automatically.
|
|
117
|
+
|
|
118
|
+
### Pinning a Version (Recommended for Production)
|
|
119
|
+
|
|
120
|
+
Pin a specific API version to protect your integration from breaking changes:
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
const client = new GptClient({
|
|
124
|
+
baseUrl: "https://api.gpt-core.com",
|
|
125
|
+
apiKey: "sk_app_...",
|
|
126
|
+
apiVersion: "2025-12-03", // Pin to this version
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Reading the Active Version
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
// The version the SDK is configured to send
|
|
134
|
+
console.log(client.apiVersion);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Response Header
|
|
138
|
+
|
|
139
|
+
Every API response includes the version that was used to process the request:
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
x-api-version: 2025-12-03
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Discovering Available Versions
|
|
146
|
+
|
|
147
|
+
List all supported API versions and their changelogs:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
GET /api-versions
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
This returns the full list of versions with descriptions and deprecation status.
|
|
154
|
+
|
|
155
|
+
## Configuration
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
const client = new GptClient({
|
|
159
|
+
// API base URL (falls back to GPTCORE_BASE_URL env var)
|
|
160
|
+
baseUrl: "https://api.gpt-core.com",
|
|
161
|
+
|
|
162
|
+
// Authentication (provide one or both; falls back to env vars)
|
|
163
|
+
apiKey: "sk_app_...", // GPTCORE_API_KEY
|
|
164
|
+
token: "eyJhbGc...", // GPTCORE_TOKEN
|
|
165
|
+
|
|
166
|
+
// API version (optional, uses SDK default if not specified)
|
|
167
|
+
apiVersion: "2025-12-03",
|
|
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
|
|
191
|
+
security: {
|
|
192
|
+
requireHttps: false, // Throw InsecureConnectionError on HTTP (default: warn only)
|
|
193
|
+
},
|
|
194
|
+
|
|
195
|
+
// Retry configuration (default: 3 retries with exponential backoff)
|
|
196
|
+
retry: {
|
|
197
|
+
maxRetries: 3,
|
|
198
|
+
initialDelay: 1000,
|
|
199
|
+
maxDelay: 32000,
|
|
200
|
+
retryableStatusCodes: [429, 500, 502, 503, 504],
|
|
201
|
+
},
|
|
202
|
+
|
|
203
|
+
// Disable retries
|
|
204
|
+
// retry: false,
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Security
|
|
209
|
+
|
|
210
|
+
### HTTPS Enforcement
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
// Development: Warns only (localhost is always allowed)
|
|
214
|
+
const devClient = new GptClient({
|
|
215
|
+
baseUrl: "http://localhost:33333",
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
// Production: Blocks HTTP connections
|
|
219
|
+
const prodClient = new GptClient({
|
|
220
|
+
baseUrl: "https://api.gpt-core.com",
|
|
221
|
+
security: { requireHttps: true },
|
|
222
|
+
});
|
|
223
|
+
```
|
|
224
|
+
|
|
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
|
+
});
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### API Key Validation
|
|
241
|
+
|
|
242
|
+
The SDK validates API key format and warns about elevated privilege keys:
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
// Valid prefixes: sk_tenant_*, sk_app_*, sk_srv_*, sk_sys_*
|
|
246
|
+
// sk_sys_* keys trigger warnings (elevated privileges)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## API Reference
|
|
250
|
+
|
|
251
|
+
### Identity
|
|
252
|
+
|
|
253
|
+
Manage users, authentication, and API keys.
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
// Login
|
|
257
|
+
const result = await client.identity.login(email, password);
|
|
258
|
+
client.setToken(result.token);
|
|
259
|
+
|
|
260
|
+
// Register
|
|
261
|
+
const user = await client.identity.register(
|
|
262
|
+
email,
|
|
263
|
+
password,
|
|
264
|
+
passwordConfirmation,
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
// Get current user
|
|
268
|
+
const user = await client.identity.me();
|
|
269
|
+
|
|
270
|
+
// Get user profile
|
|
271
|
+
const profile = await client.identity.profile();
|
|
272
|
+
|
|
273
|
+
// API Keys
|
|
274
|
+
const keys = await client.identity.apiKeys.list();
|
|
275
|
+
const newKey = await client.identity.apiKeys.create("Production Key");
|
|
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");
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### Platform
|
|
282
|
+
|
|
283
|
+
Manage applications, workspaces, tenants, and invitations.
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
// Applications
|
|
287
|
+
const apps = await client.platform.applications.list();
|
|
288
|
+
const app = await client.platform.applications.getBySlug("my-app");
|
|
289
|
+
|
|
290
|
+
// Workspaces
|
|
291
|
+
const workspaces = await client.platform.workspaces.list();
|
|
292
|
+
const myWorkspaces = await client.platform.workspaces.mine();
|
|
293
|
+
const workspace = await client.platform.workspaces.create(
|
|
294
|
+
"New Workspace",
|
|
295
|
+
"new-workspace",
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
// Invitations
|
|
299
|
+
await client.platform.invitations.create(
|
|
300
|
+
"colleague@example.com",
|
|
301
|
+
"editor",
|
|
302
|
+
"workspace",
|
|
303
|
+
"workspace-id",
|
|
304
|
+
);
|
|
305
|
+
await client.platform.invitations.accept("invitation-id");
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Agents
|
|
309
|
+
|
|
310
|
+
Create and manage AI agents.
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
// CRUD
|
|
314
|
+
const agents = await client.agents.list();
|
|
315
|
+
const agent = await client.agents.create(
|
|
316
|
+
"Support Agent",
|
|
317
|
+
"You are a helpful assistant",
|
|
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
|
|
332
|
+
|
|
333
|
+
Semantic search, embeddings, and conversations.
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
// Search
|
|
337
|
+
const results = await client.ai.search("quarterly earnings");
|
|
338
|
+
const advanced = await client.ai.searchAdvanced("revenue data", { limit: 20 });
|
|
339
|
+
|
|
340
|
+
// Embeddings
|
|
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" });
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Threads
|
|
349
|
+
|
|
350
|
+
Real-time messaging threads.
|
|
351
|
+
|
|
352
|
+
```typescript
|
|
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
|
+
```
|
|
366
|
+
|
|
367
|
+
### Extraction
|
|
368
|
+
|
|
369
|
+
Upload and process documents.
|
|
370
|
+
|
|
371
|
+
```typescript
|
|
372
|
+
// Upload
|
|
373
|
+
const doc = await client.extraction.documents.upload(file);
|
|
374
|
+
const status = await client.extraction.documents.status(doc.id);
|
|
375
|
+
|
|
376
|
+
// Results
|
|
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" });
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### Storage
|
|
385
|
+
|
|
386
|
+
Manage buckets and files.
|
|
387
|
+
|
|
388
|
+
```typescript
|
|
389
|
+
// Buckets
|
|
390
|
+
const buckets = await client.storage.buckets.list();
|
|
391
|
+
const bucket = await client.storage.buckets.create("uploads", "private");
|
|
392
|
+
|
|
393
|
+
// Presigned URLs
|
|
394
|
+
const uploadUrl = await client.storage.signUpload("image.png", "image/png");
|
|
395
|
+
const downloadUrl = await client.storage.signDownload("object-id");
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### Billing
|
|
399
|
+
|
|
400
|
+
Access wallet, plans, and payment methods.
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
// Wallet
|
|
404
|
+
const wallet = await client.billing.wallet.get();
|
|
405
|
+
|
|
406
|
+
// Plans
|
|
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");
|
|
444
|
+
```
|
|
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-platform 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
|
+
|
|
488
|
+
## Advanced Features
|
|
489
|
+
|
|
490
|
+
### Error Handling
|
|
491
|
+
|
|
492
|
+
The SDK provides detailed error classes:
|
|
493
|
+
|
|
494
|
+
```typescript
|
|
495
|
+
import {
|
|
496
|
+
AuthenticationError,
|
|
497
|
+
AuthorizationError,
|
|
498
|
+
NotFoundError,
|
|
499
|
+
ValidationError,
|
|
500
|
+
RateLimitError,
|
|
501
|
+
ServerError,
|
|
502
|
+
} from "@gpt-platform client";
|
|
503
|
+
|
|
504
|
+
try {
|
|
505
|
+
await client.identity.login("user@example.com", "wrong-password");
|
|
506
|
+
} catch (error) {
|
|
507
|
+
if (error instanceof AuthenticationError) {
|
|
508
|
+
console.error("Invalid credentials:", error.message);
|
|
509
|
+
console.error("Request ID:", error.requestId);
|
|
510
|
+
} else if (error instanceof ValidationError) {
|
|
511
|
+
console.error("Validation errors:", error.errors);
|
|
512
|
+
} else if (error instanceof RateLimitError) {
|
|
513
|
+
console.error(`Rate limited. Retry after ${error.retryAfter}s`);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
### Pagination
|
|
519
|
+
|
|
520
|
+
Easily iterate over large datasets with built-in memory protection:
|
|
521
|
+
|
|
522
|
+
```typescript
|
|
523
|
+
import { paginateAll } from "@gpt-platform client";
|
|
524
|
+
|
|
525
|
+
// With limit (default: 10,000)
|
|
526
|
+
for await (const item of paginateAll(fetcher, { pageSize: 50, limit: 1000 })) {
|
|
527
|
+
// Process items
|
|
528
|
+
}
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
**Pagination Safety:**
|
|
532
|
+
|
|
533
|
+
- **Default Limit**: 10,000 items max (prevents memory exhaustion)
|
|
534
|
+
- **Warning**: Shows warning when fetching > 1,000 items
|
|
535
|
+
- **Configurable**: Set custom `limit` for your use case
|
|
536
|
+
|
|
537
|
+
### Streaming
|
|
538
|
+
|
|
539
|
+
Stream AI responses in real-time:
|
|
540
|
+
|
|
541
|
+
```typescript
|
|
542
|
+
import { streamMessage } from "@gpt-platform client";
|
|
543
|
+
|
|
544
|
+
const response = await fetch(streamingEndpoint, {
|
|
545
|
+
method: "POST",
|
|
546
|
+
headers: { Accept: "text/event-stream" },
|
|
547
|
+
body: JSON.stringify({ content: "Hello AI" }),
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
for await (const chunk of streamMessage(response)) {
|
|
551
|
+
if (chunk.type === "content") {
|
|
552
|
+
process.stdout.write(chunk.content);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
### Retry Logic
|
|
558
|
+
|
|
559
|
+
Automatic retries with exponential backoff and circuit breaker:
|
|
560
|
+
|
|
561
|
+
```typescript
|
|
562
|
+
const client = new GptClient({
|
|
563
|
+
baseUrl: "https://api.gpt-core.com",
|
|
564
|
+
token: "token",
|
|
565
|
+
retry: {
|
|
566
|
+
maxRetries: 5,
|
|
567
|
+
initialDelay: 1000,
|
|
568
|
+
maxDelay: 32000,
|
|
569
|
+
},
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
// Disable retries
|
|
573
|
+
const noRetryClient = new GptClient({
|
|
574
|
+
retry: false,
|
|
575
|
+
});
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
### Raw Functions
|
|
579
|
+
|
|
580
|
+
All 403+ generated functions remain available as named exports for power users:
|
|
581
|
+
|
|
582
|
+
```typescript
|
|
583
|
+
import { getAgents, postUsersAuthLogin } from "@gpt-platform client";
|
|
584
|
+
|
|
585
|
+
const { data, error } = await getAgents({ client: myClientInstance });
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
## TypeScript Support
|
|
589
|
+
|
|
590
|
+
The SDK is written in TypeScript and provides full type safety:
|
|
591
|
+
|
|
592
|
+
```typescript
|
|
593
|
+
import type {
|
|
594
|
+
BaseClientConfig,
|
|
595
|
+
AppInfo,
|
|
596
|
+
Logger,
|
|
597
|
+
LogLevel,
|
|
598
|
+
RequestOptions,
|
|
599
|
+
} from "@gpt-platform client";
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
## License
|
|
603
|
+
|
|
604
|
+
MIT
|
|
605
|
+
|
|
606
|
+
## Support
|
|
607
|
+
|
|
608
|
+
- Documentation: https://docs.gpt-core.com
|
|
609
|
+
- Issues: https://github.com/GPT-Integrators/gpt-core-sdks/issues
|