hydra-aidirector 1.6.1 → 1.6.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,19 +1,17 @@
1
1
  # hydra-aidirector
2
2
 
3
- The official TypeScript SDK for [Hydra](https://hydrai.dev).
3
+ One client. One secret. One AI gateway.
4
4
 
5
- Hydra gives your app one stable AI gateway instead of a pile of provider glue. You send one request. Hydra handles routing, failover, cache behavior, JSON recovery, and operational visibility behind the same API.
5
+ `hydra-aidirector` is the official TypeScript SDK for [Hydra](https://hydrai.dev/docs). It gives your app one clean path for generation, failover chains, structured output, scoped caching, streaming, usage, health, and webhooks without making you glue providers together by hand.
6
6
 
7
7
  ## Install
8
8
 
9
9
  ```bash
10
10
  bun add hydra-aidirector
11
- # or
11
+ ```
12
+
13
+ ```bash
12
14
  npm install hydra-aidirector
13
- # or
14
- pnpm add hydra-aidirector
15
- # or
16
- yarn add hydra-aidirector
17
15
  ```
18
16
 
19
17
  ## Quick Start
@@ -23,33 +21,34 @@ import { Hydra } from 'hydra-aidirector';
23
21
 
24
22
  const client = new Hydra({
25
23
  secretKey: process.env.HYDRA_SECRET_KEY!, // hyd_sk_...
26
- baseUrl: 'https://your-hydra-instance.com',
24
+ baseUrl: process.env.HYDRA_BASE_URL!, // https://your-hydra-instance.com
27
25
  });
28
26
 
29
27
  const result = await client.generate({
30
28
  chainId: 'support-replies',
31
- prompt: 'Write 3 concise onboarding emails as JSON',
29
+ prompt: 'Return 3 short onboarding emails as JSON.',
32
30
  });
33
31
 
34
32
  if (result.success) {
35
33
  console.log(result.data.valid);
34
+ } else {
35
+ console.error(result.error);
36
36
  }
37
37
  ```
38
38
 
39
- ## What You Get
39
+ ## Why Teams Use It
40
40
 
41
+ - One typed client for generation, streaming, usage, health, and webhooks.
41
42
  - Automatic failover across the models in your chain.
42
- - JSON extraction and repair when providers return noisy output.
43
- - User-safe caching with request-level cache controls.
44
- - Streaming for long responses.
45
- - Batch generation for parallel prompt execution.
46
- - Usage, health, and webhook management from the same client.
43
+ - Structured output recovery when providers return noisy JSON.
44
+ - Cache controls that let you keep shared prompts fast and sensitive prompts private.
45
+ - One request trail to inspect when latency, cost, or provider behavior starts drifting.
47
46
 
48
- ## Generation Modes
47
+ ## How Generation Works
49
48
 
50
- Hydra uses the optimized 3-step flow by default for simple requests. That keeps the fast path cheap and responsive.
49
+ Hydra uses the optimized 3-step flow by default for simple requests. That path keeps the fast lane lean by moving the long model call out of the request path that fronts your app.
51
50
 
52
- When you ask for features that require the full server pipeline, the SDK automatically falls back to the legacy endpoint. That includes:
51
+ When a request needs the full server pipeline, the SDK automatically falls back to the legacy endpoint. That includes:
53
52
 
54
53
  - `schema`
55
54
  - `noCache`
@@ -58,7 +57,7 @@ When you ask for features that require the full server pipeline, the SDK automat
58
57
  - `strictJson`
59
58
  - `maxRetries`
60
59
 
61
- You can also force the legacy endpoint yourself:
60
+ You can also force the legacy path yourself:
62
61
 
63
62
  ```ts
64
63
  await client.generate({
@@ -70,12 +69,12 @@ await client.generate({
70
69
 
71
70
  ## Structured Output
72
71
 
73
- Use `schema` when you want validated JSON back:
72
+ Use `schema` when the response shape matters:
74
73
 
75
74
  ```ts
76
75
  const result = await client.generate({
77
76
  chainId: 'invoice-parser',
78
- prompt: 'Extract invoice fields',
77
+ prompt: 'Extract the invoice fields.',
79
78
  schema: {
80
79
  invoiceNumber: 'string',
81
80
  amount: 'number',
@@ -85,38 +84,38 @@ const result = await client.generate({
85
84
  });
86
85
  ```
87
86
 
88
- If the provider returns malformed JSON, Hydra will still try to recover it before the request fails.
87
+ If the provider comes back with malformed JSON, Hydra will still try to recover the payload before the request fails.
89
88
 
90
89
  ## Cache Control
91
90
 
92
- Use request-level cache controls when the prompt should behave differently from the default path:
91
+ Use request-level cache controls when freshness or privacy matters:
93
92
 
94
93
  ```ts
95
94
  await client.generate({
96
95
  chainId: 'account-summary',
97
- prompt: 'Summarize this customer account',
96
+ prompt: 'Summarize this customer account.',
98
97
  cacheScope: 'user',
99
98
  });
100
99
 
101
100
  await client.generate({
102
101
  chainId: 'pricing-faq',
103
- prompt: 'Return the current pricing summary',
102
+ prompt: 'Return the current pricing summary.',
104
103
  cacheScope: 'global',
105
104
  });
106
105
 
107
106
  await client.generate({
108
107
  chainId: 'one-off',
109
- prompt: 'Generate a fresh variant',
108
+ prompt: 'Generate a fresh variant.',
110
109
  noCache: true,
111
110
  });
112
111
  ```
113
112
 
114
- You can also tune cache matching:
113
+ Tune cache matching when you want better reuse:
115
114
 
116
115
  ```ts
117
116
  await client.generate({
118
117
  chainId: 'reporting',
119
- prompt: 'Generate the weekly report',
118
+ prompt: 'Generate the weekly report.',
120
119
  cacheQuality: 'HIGH',
121
120
  });
122
121
  ```
@@ -129,7 +128,7 @@ Stream parsed objects as they arrive:
129
128
  await client.generateStream(
130
129
  {
131
130
  chainId: 'catalog-generator',
132
- prompt: 'Generate 50 product blurbs as JSON',
131
+ prompt: 'Generate 50 product blurbs as JSON.',
133
132
  },
134
133
  {
135
134
  onObject: (object, index) => {
@@ -159,9 +158,9 @@ const batch = await client.generateBatch('catalog-generator', [
159
158
  console.log(batch.summary);
160
159
  ```
161
160
 
162
- ## Files
161
+ ## File Attachments
163
162
 
164
- Send file attachments as base64:
163
+ Send files as base64 and let Hydra handle the processing path:
165
164
 
166
165
  ```ts
167
166
  import fs from 'node:fs';
@@ -170,7 +169,7 @@ const file = fs.readFileSync('report.pdf');
170
169
 
171
170
  const result = await client.generate({
172
171
  chainId: 'document-analysis',
173
- prompt: 'Summarize this report',
172
+ prompt: 'Summarize this report.',
174
173
  files: [
175
174
  {
176
175
  data: file.toString('base64'),
@@ -181,7 +180,7 @@ const result = await client.generate({
181
180
  });
182
181
  ```
183
182
 
184
- ## Usage and Health
183
+ ## Usage And Health
185
184
 
186
185
  Get normalized usage metrics:
187
186
 
@@ -200,7 +199,7 @@ Basic health:
200
199
 
201
200
  ```ts
202
201
  const health = await client.health();
203
- console.log(health.ok, health.latencyMs);
202
+ console.log(health.ok, health.latencyMs, health.version);
204
203
  ```
205
204
 
206
205
  Detailed health requires an admin key:
@@ -242,7 +241,7 @@ setTimeout(() => controller.abort(), 5000);
242
241
 
243
242
  await client.generate({
244
243
  chainId: 'long-job',
245
- prompt: 'Generate a long report',
244
+ prompt: 'Generate a long report.',
246
245
  signal: controller.signal,
247
246
  });
248
247
  ```
@@ -261,11 +260,11 @@ import {
261
260
  try {
262
261
  await client.generate({
263
262
  chainId: 'support-replies',
264
- prompt: 'Write a response',
263
+ prompt: 'Write a response.',
265
264
  });
266
265
  } catch (error) {
267
266
  if (error instanceof AuthenticationError) {
268
- console.error('The Hydra secret key is invalid.');
267
+ console.error('Your Hydra secret key is invalid.');
269
268
  } else if (error instanceof QuotaExceededError) {
270
269
  console.error(error.tier, error.used, error.limit);
271
270
  } else if (error instanceof RateLimitError) {
@@ -297,8 +296,15 @@ try {
297
296
  ## Requirements
298
297
 
299
298
  - Node.js 18+
299
+ - Bun 1.0+ or another runtime with `fetch`
300
300
  - TypeScript 5+ for typed projects
301
301
 
302
+ ## Get Started
303
+
304
+ - Docs: [hydrai.dev/docs](https://hydrai.dev/docs)
305
+ - Dashboard: [hydrai.dev/signin](https://hydrai.dev/signin)
306
+ - Contact: [hydrai.dev/contact](https://hydrai.dev/contact)
307
+
302
308
  ## License
303
309
 
304
310
  MIT
package/dist/index.d.mts CHANGED
@@ -15,7 +15,7 @@ interface HydraConfig {
15
15
  /**
16
16
  * API base URL
17
17
  * @default 'http://localhost:3000' in development
18
- * @example 'https://api.hydrai.dev'
18
+ * @example 'https://your-hydra-instance.com'
19
19
  */
20
20
  baseUrl?: string;
21
21
  /**
@@ -698,7 +698,7 @@ interface WebhookConfig {
698
698
  *
699
699
  * const client = new Hydra({
700
700
  * secretKey: process.env.HYDRA_SECRET_KEY!,
701
- * baseUrl: 'https://api.hydrai.dev',
701
+ * baseUrl: 'https://your-hydra-instance.com',
702
702
  * });
703
703
  *
704
704
  * const result = await client.generate({
package/dist/index.d.ts CHANGED
@@ -15,7 +15,7 @@ interface HydraConfig {
15
15
  /**
16
16
  * API base URL
17
17
  * @default 'http://localhost:3000' in development
18
- * @example 'https://api.hydrai.dev'
18
+ * @example 'https://your-hydra-instance.com'
19
19
  */
20
20
  baseUrl?: string;
21
21
  /**
@@ -698,7 +698,7 @@ interface WebhookConfig {
698
698
  *
699
699
  * const client = new Hydra({
700
700
  * secretKey: process.env.HYDRA_SECRET_KEY!,
701
- * baseUrl: 'https://api.hydrai.dev',
701
+ * baseUrl: 'https://your-hydra-instance.com',
702
702
  * });
703
703
  *
704
704
  * const result = await client.generate({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hydra-aidirector",
3
- "version": "1.6.1",
4
- "description": "Official TypeScript SDK for Hydra - Intelligent AI API Gateway with automatic failover, caching, and JSON extraction",
3
+ "version": "1.6.2",
4
+ "description": "Official TypeScript SDK for Hydra. Generate, stream, fail over models, control cache scope, and manage AI operations from one client.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
@@ -38,6 +38,7 @@
38
38
  },
39
39
  "keywords": [
40
40
  "ai",
41
+ "ai-sdk",
41
42
  "api",
42
43
  "gateway",
43
44
  "gemini",
@@ -49,6 +50,10 @@
49
50
  "typescript",
50
51
  "json",
51
52
  "cache",
53
+ "structured-output",
54
+ "streaming",
55
+ "webhooks",
56
+ "observability",
52
57
  "hmac"
53
58
  ],
54
59
  "author": {
@@ -56,13 +61,9 @@
56
61
  "url": "https://hydrai.dev"
57
62
  },
58
63
  "license": "MIT",
59
- "homepage": "https://hydrai.dev",
64
+ "homepage": "https://hydrai.dev/docs",
60
65
  "bugs": {
61
- "url": "https://github.com/hydrai/client/issues"
62
- },
63
- "repository": {
64
- "type": "git",
65
- "url": "git+https://github.com/hydrai/client.git"
66
+ "url": "https://hydrai.dev/contact"
66
67
  },
67
68
  "publishConfig": {
68
69
  "access": "public",