@kaana.ai/contracts 8.9.0 → 8.11.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.
package/dist/index.d.ts CHANGED
@@ -26,6 +26,7 @@ export * from './public/money.js';
26
26
  export * from './public/policy.js';
27
27
  export * from './public/providerPreferences.js';
28
28
  export * from './public/realtime.js';
29
+ export * from './public/rerank.js';
29
30
  export * from './public/responses.js';
30
31
  export * from './public/streamEvents.js';
31
32
  export * from './public/version.js';
package/dist/index.js CHANGED
@@ -26,6 +26,7 @@ export * from './public/money.js';
26
26
  export * from './public/policy.js';
27
27
  export * from './public/providerPreferences.js';
28
28
  export * from './public/realtime.js';
29
+ export * from './public/rerank.js';
29
30
  export * from './public/responses.js';
30
31
  export * from './public/streamEvents.js';
31
32
  export * from './public/version.js';
@@ -314,10 +314,10 @@ export declare const routingProfileSchema: z.ZodObject<{
314
314
  displayName: z.ZodString;
315
315
  description: z.ZodOptional<z.ZodString>;
316
316
  optimiseFor: z.ZodEnum<{
317
+ price: "price";
317
318
  latency: "latency";
318
319
  throughput: "throughput";
319
320
  quality: "quality";
320
- price: "price";
321
321
  balanced: "balanced";
322
322
  }>;
323
323
  candidates: z.ZodArray<z.ZodObject<{
@@ -40,6 +40,7 @@ export declare const grantOperationSchema: z.ZodEnum<{
40
40
  images_generations: "images_generations";
41
41
  audio_transcriptions: "audio_transcriptions";
42
42
  audio_speech: "audio_speech";
43
+ rerank: "rerank";
43
44
  realtime_session: "realtime_session";
44
45
  }>;
45
46
  /**
@@ -101,6 +102,7 @@ export declare const inferenceAuthorizationRequestSchema: z.ZodObject<{
101
102
  images_generations: "images_generations";
102
103
  audio_transcriptions: "audio_transcriptions";
103
104
  audio_speech: "audio_speech";
105
+ rerank: "rerank";
104
106
  realtime_session: "realtime_session";
105
107
  }>;
106
108
  target: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -181,6 +183,7 @@ export declare const authorizationRequestSchema: z.ZodDiscriminatedUnion<[z.ZodO
181
183
  images_generations: "images_generations";
182
184
  audio_transcriptions: "audio_transcriptions";
183
185
  audio_speech: "audio_speech";
186
+ rerank: "rerank";
184
187
  realtime_session: "realtime_session";
185
188
  }>;
186
189
  target: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -383,6 +386,7 @@ export declare const grantSchema: z.ZodObject<{
383
386
  images_generations: "images_generations";
384
387
  audio_transcriptions: "audio_transcriptions";
385
388
  audio_speech: "audio_speech";
389
+ rerank: "rerank";
386
390
  realtime_session: "realtime_session";
387
391
  }>;
388
392
  issuedAt: z.ZodString;
@@ -65,6 +65,7 @@ export const grantOperationSchema = z.enum([
65
65
  'images_generations',
66
66
  'decisions',
67
67
  'realtime_session',
68
+ 'rerank',
68
69
  ]);
69
70
  /**
70
71
  * What the caller asked to be served: a model line, optionally pinned to a
@@ -250,9 +250,14 @@ export declare const chatCompletionsRequestSchema: z.ZodObject<{
250
250
  fp32: "fp32";
251
251
  }>>>;
252
252
  sort: z.ZodOptional<z.ZodEnum<{
253
+ price: "price";
253
254
  latency: "latency";
254
255
  throughput: "throughput";
255
256
  }>>;
257
+ max_price: z.ZodOptional<z.ZodObject<{
258
+ prompt: z.ZodOptional<z.ZodNumber>;
259
+ completion: z.ZodOptional<z.ZodNumber>;
260
+ }, z.core.$strict>>;
256
261
  preferred_max_latency: z.ZodOptional<z.ZodNumber>;
257
262
  preferred_min_throughput: z.ZodOptional<z.ZodNumber>;
258
263
  }, z.core.$strict>>;
@@ -9,11 +9,17 @@
9
9
  * rather than widened.
10
10
  *
11
11
  * The names are OpenRouter's, so a client written for OpenRouter's `provider`
12
- * object works, and only the controls Kaana can honour are accepted:
13
- * `sort: "price"`, `max_price`, `zdr`, `data_collection`, `preferred_*` with a
14
- * percentile object, and `enforce_distillable_text` are refused by `.strict()`
15
- * rather than silently ignored. `max_price` and the data policy stay Oxy's:
16
- * Kaana never prices, and Oxy applies data policy when it computes the grant.
12
+ * object works, and only the controls Kaana can honour are accepted: `zdr`,
13
+ * `data_collection`, `preferred_*` with a percentile object and
14
+ * `enforce_distillable_text` are refused by `.strict()` rather than silently
15
+ * ignored, because the data policy is Oxy's and is applied when it computes the
16
+ * grant.
17
+ *
18
+ * `max_price` and `sort: "price"` read the DECLARED LIST PRICE of a model line,
19
+ * the price Oxy rates the grant at, in USD per million tokens. They are about
20
+ * which model line serves the request, because every route of one line costs
21
+ * the customer the same: they never expose an amount, and a line whose price
22
+ * the catalogue does not state is neither within a ceiling nor cheap.
17
23
  *
18
24
  * Provider names here are Kaana provider slugs as a caller sees them in the
19
25
  * catalogue. A response never names one.
@@ -55,9 +61,14 @@ export declare const providerPreferencesSchema: z.ZodObject<{
55
61
  fp32: "fp32";
56
62
  }>>>;
57
63
  sort: z.ZodOptional<z.ZodEnum<{
64
+ price: "price";
58
65
  latency: "latency";
59
66
  throughput: "throughput";
60
67
  }>>;
68
+ max_price: z.ZodOptional<z.ZodObject<{
69
+ prompt: z.ZodOptional<z.ZodNumber>;
70
+ completion: z.ZodOptional<z.ZodNumber>;
71
+ }, z.core.$strict>>;
61
72
  preferred_max_latency: z.ZodOptional<z.ZodNumber>;
62
73
  preferred_min_throughput: z.ZodOptional<z.ZodNumber>;
63
74
  }, z.core.$strict>;
@@ -9,11 +9,17 @@
9
9
  * rather than widened.
10
10
  *
11
11
  * The names are OpenRouter's, so a client written for OpenRouter's `provider`
12
- * object works, and only the controls Kaana can honour are accepted:
13
- * `sort: "price"`, `max_price`, `zdr`, `data_collection`, `preferred_*` with a
14
- * percentile object, and `enforce_distillable_text` are refused by `.strict()`
15
- * rather than silently ignored. `max_price` and the data policy stay Oxy's:
16
- * Kaana never prices, and Oxy applies data policy when it computes the grant.
12
+ * object works, and only the controls Kaana can honour are accepted: `zdr`,
13
+ * `data_collection`, `preferred_*` with a percentile object and
14
+ * `enforce_distillable_text` are refused by `.strict()` rather than silently
15
+ * ignored, because the data policy is Oxy's and is applied when it computes the
16
+ * grant.
17
+ *
18
+ * `max_price` and `sort: "price"` read the DECLARED LIST PRICE of a model line,
19
+ * the price Oxy rates the grant at, in USD per million tokens. They are about
20
+ * which model line serves the request, because every route of one line costs
21
+ * the customer the same: they never expose an amount, and a line whose price
22
+ * the catalogue does not state is neither within a ceiling nor cheap.
17
23
  *
18
24
  * Provider names here are Kaana provider slugs as a caller sees them in the
19
25
  * catalogue. A response never names one.
@@ -58,8 +64,26 @@ export const providerPreferencesSchema = z
58
64
  require_parameters: z.boolean().optional(),
59
65
  /** Keep only routes published at one of these quantizations; `unknown` admits unstated ones. */
60
66
  quantizations: z.array(providerQuantizationSchema).min(1).max(12).optional(),
61
- /** Prefer the route with the lowest recent latency or the highest recent throughput. */
62
- sort: z.enum(['latency', 'throughput']).optional(),
67
+ /**
68
+ * Prefer the model line with the lowest declared list price, or the route
69
+ * with the lowest recent latency or the highest recent throughput.
70
+ */
71
+ sort: z.enum(['price', 'latency', 'throughput']).optional(),
72
+ /**
73
+ * A ceiling on the declared list price of the model line, in USD per million
74
+ * tokens. A line over it, or one whose price is not stated, is not used; the
75
+ * request is refused rather than served above it.
76
+ */
77
+ max_price: z
78
+ .object({
79
+ prompt: z.number().positive().max(1_000_000).optional(),
80
+ completion: z.number().positive().max(1_000_000).optional(),
81
+ })
82
+ .strict()
83
+ .refine((ceiling) => ceiling.prompt !== undefined || ceiling.completion !== undefined, {
84
+ message: 'max_price names prompt, completion or both',
85
+ })
86
+ .optional(),
63
87
  /** Seconds. A route slower than this recently is tried later, never excluded (p50). */
64
88
  preferred_max_latency: z.number().positive().max(600).optional(),
65
89
  /** Output tokens per second. A route slower than this recently is tried later, never excluded (p50). */
@@ -0,0 +1,38 @@
1
+ /**
2
+ * `POST /v1/rerank` — rank documents by relevance to a query.
3
+ *
4
+ * New in contract set 8.11.0, CONTRACT ONLY: these shapes and the `rerank` grant
5
+ * operation are declared so Oxy can support the operation before Kaana serves
6
+ * it. Kaana does not serve the route yet and emits no `rerank` operation.
7
+ *
8
+ * Version 1 takes string documents only. The response carries a relevance score
9
+ * per document and the token usage; it never carries an amount.
10
+ */
11
+ import { z } from 'zod';
12
+ /** The most documents one rerank request may carry. */
13
+ export declare const MAX_RERANK_DOCUMENTS = 1000;
14
+ export declare const rerankRequestSchema: z.ZodObject<{
15
+ model: z.ZodString;
16
+ query: z.ZodString;
17
+ documents: z.ZodArray<z.ZodString>;
18
+ top_n: z.ZodOptional<z.ZodNumber>;
19
+ return_documents: z.ZodOptional<z.ZodBoolean>;
20
+ user: z.ZodOptional<z.ZodString>;
21
+ }, z.core.$strict>;
22
+ export declare const rerankResponseSchema: z.ZodObject<{
23
+ id: z.ZodString;
24
+ model: z.ZodString;
25
+ results: z.ZodArray<z.ZodObject<{
26
+ index: z.ZodNumber;
27
+ relevance_score: z.ZodNumber;
28
+ document: z.ZodOptional<z.ZodObject<{
29
+ text: z.ZodString;
30
+ }, z.core.$strict>>;
31
+ }, z.core.$strict>>;
32
+ usage: z.ZodObject<{
33
+ prompt_tokens: z.ZodNumber;
34
+ total_tokens: z.ZodNumber;
35
+ }, z.core.$strict>;
36
+ }, z.core.$strict>;
37
+ export type RerankRequest = z.infer<typeof rerankRequestSchema>;
38
+ export type RerankResponse = z.infer<typeof rerankResponseSchema>;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * `POST /v1/rerank` — rank documents by relevance to a query.
3
+ *
4
+ * New in contract set 8.11.0, CONTRACT ONLY: these shapes and the `rerank` grant
5
+ * operation are declared so Oxy can support the operation before Kaana serves
6
+ * it. Kaana does not serve the route yet and emits no `rerank` operation.
7
+ *
8
+ * Version 1 takes string documents only. The response carries a relevance score
9
+ * per document and the token usage; it never carries an amount.
10
+ */
11
+ import { z } from 'zod';
12
+ import { maxUtf16Length, minUtf16Length } from '../stringBounds.js';
13
+ import { generationIdSchema, modelReferenceSchema } from './identifiers.js';
14
+ /** The most documents one rerank request may carry. */
15
+ export const MAX_RERANK_DOCUMENTS = 1000;
16
+ export const rerankRequestSchema = z
17
+ .object({
18
+ /** `publisher/model` or `publisher/model@revision`. */
19
+ model: modelReferenceSchema,
20
+ query: z.string().check(minUtf16Length(1)),
21
+ /** String documents only. */
22
+ documents: z
23
+ .array(z.string().check(minUtf16Length(1)))
24
+ .min(1)
25
+ .max(MAX_RERANK_DOCUMENTS),
26
+ /** How many of the most relevant documents to return; all when absent. */
27
+ top_n: z.number().int().min(1).optional(),
28
+ /** Echo each ranked document's text in its result. */
29
+ return_documents: z.boolean().optional(),
30
+ /** The delegated end-user id, attribution only (as on `/v1/embeddings`). */
31
+ user: z.string().check(minUtf16Length(1)).check(maxUtf16Length(64)).optional(),
32
+ })
33
+ .strict();
34
+ export const rerankResponseSchema = z
35
+ .object({
36
+ id: generationIdSchema,
37
+ /** The revision that produced the scores. */
38
+ model: modelReferenceSchema,
39
+ /** Most relevant first. */
40
+ results: z
41
+ .array(z
42
+ .object({
43
+ /** The position of the document in the request's `documents`. */
44
+ index: z.number().int().nonnegative(),
45
+ relevance_score: z.number(),
46
+ document: z.object({ text: z.string() }).strict().optional(),
47
+ })
48
+ .strict())
49
+ .max(MAX_RERANK_DOCUMENTS),
50
+ usage: z
51
+ .object({
52
+ prompt_tokens: z.number().int().nonnegative(),
53
+ total_tokens: z.number().int().nonnegative(),
54
+ })
55
+ .strict(),
56
+ })
57
+ .strict()
58
+ .superRefine((response, ctx) => {
59
+ const indexes = response.results.map((result) => result.index);
60
+ if (new Set(indexes).size !== indexes.length) {
61
+ ctx.addIssue({ code: 'custom', path: ['results'], message: 'result indexes must be unique' });
62
+ }
63
+ });
@@ -204,9 +204,14 @@ export declare const responsesRequestSchema: z.ZodObject<{
204
204
  fp32: "fp32";
205
205
  }>>>;
206
206
  sort: z.ZodOptional<z.ZodEnum<{
207
+ price: "price";
207
208
  latency: "latency";
208
209
  throughput: "throughput";
209
210
  }>>;
211
+ max_price: z.ZodOptional<z.ZodObject<{
212
+ prompt: z.ZodOptional<z.ZodNumber>;
213
+ completion: z.ZodOptional<z.ZodNumber>;
214
+ }, z.core.$strict>>;
210
215
  preferred_max_latency: z.ZodOptional<z.ZodNumber>;
211
216
  preferred_min_throughput: z.ZodOptional<z.ZodNumber>;
212
217
  }, z.core.$strict>>;
@@ -100,7 +100,7 @@
100
100
  * change to, say, the catalogue reject every in-flight inference request; the
101
101
  * per-shape `schemaVersion` is what a message is validated against.
102
102
  */
103
- export declare const INFERENCE_CONTRACT_VERSION = "8.9.0";
103
+ export declare const INFERENCE_CONTRACT_VERSION = "8.11.0";
104
104
  /**
105
105
  * Contract set 4.0.0 (Kaana ADR 0002) is the first published as
106
106
  * `@kaana.ai/contracts`. MAJOR because the set changed hands and split in two:
@@ -230,6 +230,17 @@ export declare const INFERENCE_CONTRACT_VERSION = "8.9.0";
230
230
  * request member only: the signed grant and envelope are unchanged, and a
231
231
  * response carries no new body member, so every older reader parses what 8.9.0
232
232
  * serves.
233
+ *
234
+ * Contract set 8.10.0 is additive: `max_price` and `sort: "price"` in the
235
+ * `provider` routing preference (`providerPreferencesSchema`, Kaana ADR 0008).
236
+ * Both read the declared list price of a model line, in USD per million tokens.
237
+ * Public request members only: the signed grant and envelope are unchanged and
238
+ * no response carries an amount.
239
+ *
240
+ * Contract set 8.11.0 is additive and CONTRACT ONLY: the `rerank` grant
241
+ * operation (`grantOperationSchema`, last member) and the public `POST /v1/rerank`
242
+ * shapes (`rerankRequestSchema`, `rerankResponseSchema`). Kaana emits no `rerank`
243
+ * operation and serves no route yet; Oxy supports the operation first.
233
244
  */
234
245
  /** The public API's one origin and version. */
235
246
  export declare const KAANA_API_BASE_URL = "https://kaana.ai/v1";
@@ -100,7 +100,7 @@
100
100
  * change to, say, the catalogue reject every in-flight inference request; the
101
101
  * per-shape `schemaVersion` is what a message is validated against.
102
102
  */
103
- export const INFERENCE_CONTRACT_VERSION = '8.9.0';
103
+ export const INFERENCE_CONTRACT_VERSION = '8.11.0';
104
104
  /**
105
105
  * Contract set 4.0.0 (Kaana ADR 0002) is the first published as
106
106
  * `@kaana.ai/contracts`. MAJOR because the set changed hands and split in two:
@@ -230,6 +230,17 @@ export const INFERENCE_CONTRACT_VERSION = '8.9.0';
230
230
  * request member only: the signed grant and envelope are unchanged, and a
231
231
  * response carries no new body member, so every older reader parses what 8.9.0
232
232
  * serves.
233
+ *
234
+ * Contract set 8.10.0 is additive: `max_price` and `sort: "price"` in the
235
+ * `provider` routing preference (`providerPreferencesSchema`, Kaana ADR 0008).
236
+ * Both read the declared list price of a model line, in USD per million tokens.
237
+ * Public request members only: the signed grant and envelope are unchanged and
238
+ * no response carries an amount.
239
+ *
240
+ * Contract set 8.11.0 is additive and CONTRACT ONLY: the `rerank` grant
241
+ * operation (`grantOperationSchema`, last member) and the public `POST /v1/rerank`
242
+ * shapes (`rerankRequestSchema`, `rerankResponseSchema`). Kaana emits no `rerank`
243
+ * operation and serves no route yet; Oxy supports the operation first.
233
244
  */
234
245
  /** The public API's one origin and version. */
235
246
  export const KAANA_API_BASE_URL = 'https://kaana.ai/v1';
package/openapi.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "openapi": "3.1.0",
3
3
  "info": {
4
4
  "title": "Kaana API",
5
- "version": "8.9.0",
5
+ "version": "8.11.0",
6
6
  "description": "Kaana inference API. Generated from @kaana.ai/contracts; the Zod source is the authority. Accounts, applications, oxy_sk_ keys, limits and billing are managed in Oxy Console: https://console.oxy.so"
7
7
  },
8
8
  "servers": [
@@ -5506,10 +5506,27 @@
5506
5506
  "sort": {
5507
5507
  "type": "string",
5508
5508
  "enum": [
5509
+ "price",
5509
5510
  "latency",
5510
5511
  "throughput"
5511
5512
  ]
5512
5513
  },
5514
+ "max_price": {
5515
+ "type": "object",
5516
+ "properties": {
5517
+ "prompt": {
5518
+ "type": "number",
5519
+ "exclusiveMinimum": 0,
5520
+ "maximum": 1000000
5521
+ },
5522
+ "completion": {
5523
+ "type": "number",
5524
+ "exclusiveMinimum": 0,
5525
+ "maximum": 1000000
5526
+ }
5527
+ },
5528
+ "additionalProperties": false
5529
+ },
5513
5530
  "preferred_max_latency": {
5514
5531
  "type": "number",
5515
5532
  "exclusiveMinimum": 0,
@@ -7701,6 +7718,118 @@
7701
7718
  "maxLength": 256
7702
7719
  }
7703
7720
  },
7721
+ "RerankRequest": {
7722
+ "type": "object",
7723
+ "properties": {
7724
+ "model": {
7725
+ "$ref": "#/components/schemas/ModelReference"
7726
+ },
7727
+ "query": {
7728
+ "type": "string",
7729
+ "minLength": 1
7730
+ },
7731
+ "documents": {
7732
+ "minItems": 1,
7733
+ "maxItems": 1000,
7734
+ "type": "array",
7735
+ "items": {
7736
+ "type": "string",
7737
+ "minLength": 1
7738
+ }
7739
+ },
7740
+ "top_n": {
7741
+ "type": "integer",
7742
+ "minimum": 1,
7743
+ "maximum": 9007199254740991
7744
+ },
7745
+ "return_documents": {
7746
+ "type": "boolean"
7747
+ },
7748
+ "user": {
7749
+ "type": "string",
7750
+ "minLength": 1,
7751
+ "maxLength": 64
7752
+ }
7753
+ },
7754
+ "required": [
7755
+ "model",
7756
+ "query",
7757
+ "documents"
7758
+ ],
7759
+ "additionalProperties": false
7760
+ },
7761
+ "RerankResponse": {
7762
+ "type": "object",
7763
+ "properties": {
7764
+ "id": {
7765
+ "$ref": "#/components/schemas/GenerationId"
7766
+ },
7767
+ "model": {
7768
+ "$ref": "#/components/schemas/ModelReference"
7769
+ },
7770
+ "results": {
7771
+ "maxItems": 1000,
7772
+ "type": "array",
7773
+ "items": {
7774
+ "type": "object",
7775
+ "properties": {
7776
+ "index": {
7777
+ "type": "integer",
7778
+ "minimum": 0,
7779
+ "maximum": 9007199254740991
7780
+ },
7781
+ "relevance_score": {
7782
+ "type": "number"
7783
+ },
7784
+ "document": {
7785
+ "type": "object",
7786
+ "properties": {
7787
+ "text": {
7788
+ "type": "string"
7789
+ }
7790
+ },
7791
+ "required": [
7792
+ "text"
7793
+ ],
7794
+ "additionalProperties": false
7795
+ }
7796
+ },
7797
+ "required": [
7798
+ "index",
7799
+ "relevance_score"
7800
+ ],
7801
+ "additionalProperties": false
7802
+ }
7803
+ },
7804
+ "usage": {
7805
+ "type": "object",
7806
+ "properties": {
7807
+ "prompt_tokens": {
7808
+ "type": "integer",
7809
+ "minimum": 0,
7810
+ "maximum": 9007199254740991
7811
+ },
7812
+ "total_tokens": {
7813
+ "type": "integer",
7814
+ "minimum": 0,
7815
+ "maximum": 9007199254740991
7816
+ }
7817
+ },
7818
+ "required": [
7819
+ "prompt_tokens",
7820
+ "total_tokens"
7821
+ ],
7822
+ "additionalProperties": false
7823
+ }
7824
+ },
7825
+ "required": [
7826
+ "id",
7827
+ "model",
7828
+ "results",
7829
+ "usage"
7830
+ ],
7831
+ "additionalProperties": false
7832
+ },
7704
7833
  "ResponseFormat": {
7705
7834
  "oneOf": [
7706
7835
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaana.ai/contracts",
3
- "version": "8.9.0",
3
+ "version": "8.11.0",
4
4
  "description": "Kaana inference contract: the Zod schemas of the public API at https://kaana.ai/v1 and, under /internal, of the Oxy-Kaana grant, settlement and signed lane.",
5
5
  "type": "module",
6
6
  "sideEffects": false,