@openrouter/sdk 0.12.29 → 0.12.31

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.
Files changed (70) hide show
  1. package/esm/funcs/betaResponsesSend.js +1 -0
  2. package/esm/funcs/chatSend.js +1 -0
  3. package/esm/lib/config.d.ts +2 -2
  4. package/esm/lib/config.js +2 -2
  5. package/esm/models/chatresult.d.ts +2 -0
  6. package/esm/models/chatresult.js +3 -0
  7. package/esm/models/chatstreamchunk.d.ts +2 -0
  8. package/esm/models/chatstreamchunk.js +3 -0
  9. package/esm/models/chatstreamingresponse.d.ts +14 -0
  10. package/esm/models/chatstreamingresponse.js +27 -0
  11. package/esm/models/endpointinfo.d.ts +14 -0
  12. package/esm/models/endpointinfo.js +25 -0
  13. package/esm/models/endpointsmetadata.d.ts +14 -0
  14. package/esm/models/endpointsmetadata.js +23 -0
  15. package/esm/models/errors/badgatewayresponseerror.d.ts +6 -0
  16. package/esm/models/errors/badgatewayresponseerror.js +6 -0
  17. package/esm/models/errors/badrequestresponseerror.d.ts +6 -0
  18. package/esm/models/errors/badrequestresponseerror.js +6 -0
  19. package/esm/models/errors/conflictresponseerror.d.ts +6 -0
  20. package/esm/models/errors/conflictresponseerror.js +6 -0
  21. package/esm/models/errors/edgenetworktimeoutresponseerror.d.ts +6 -0
  22. package/esm/models/errors/edgenetworktimeoutresponseerror.js +6 -0
  23. package/esm/models/errors/forbiddenresponseerror.d.ts +6 -0
  24. package/esm/models/errors/forbiddenresponseerror.js +6 -0
  25. package/esm/models/errors/internalserverresponseerror.d.ts +6 -0
  26. package/esm/models/errors/internalserverresponseerror.js +6 -0
  27. package/esm/models/errors/notfoundresponseerror.d.ts +6 -0
  28. package/esm/models/errors/notfoundresponseerror.js +6 -0
  29. package/esm/models/errors/payloadtoolargeresponseerror.d.ts +6 -0
  30. package/esm/models/errors/payloadtoolargeresponseerror.js +6 -0
  31. package/esm/models/errors/paymentrequiredresponseerror.d.ts +6 -0
  32. package/esm/models/errors/paymentrequiredresponseerror.js +6 -0
  33. package/esm/models/errors/provideroverloadedresponseerror.d.ts +6 -0
  34. package/esm/models/errors/provideroverloadedresponseerror.js +6 -0
  35. package/esm/models/errors/requesttimeoutresponseerror.d.ts +6 -0
  36. package/esm/models/errors/requesttimeoutresponseerror.js +6 -0
  37. package/esm/models/errors/serviceunavailableresponseerror.d.ts +6 -0
  38. package/esm/models/errors/serviceunavailableresponseerror.js +6 -0
  39. package/esm/models/errors/toomanyrequestsresponseerror.d.ts +6 -0
  40. package/esm/models/errors/toomanyrequestsresponseerror.js +6 -0
  41. package/esm/models/errors/unauthorizedresponseerror.d.ts +6 -0
  42. package/esm/models/errors/unauthorizedresponseerror.js +6 -0
  43. package/esm/models/errors/unprocessableentityresponseerror.d.ts +6 -0
  44. package/esm/models/errors/unprocessableentityresponseerror.js +6 -0
  45. package/esm/models/index.d.ts +11 -0
  46. package/esm/models/index.js +11 -0
  47. package/esm/models/metadatalevel.d.ts +16 -0
  48. package/esm/models/metadatalevel.js +15 -0
  49. package/esm/models/openresponsesresult.d.ts +2 -0
  50. package/esm/models/openresponsesresult.js +3 -0
  51. package/esm/models/openroutermetadata.d.ts +24 -0
  52. package/esm/models/openroutermetadata.js +33 -0
  53. package/esm/models/operations/createresponses.d.ts +4 -11
  54. package/esm/models/operations/createresponses.js +5 -20
  55. package/esm/models/operations/sendchatcompletionrequest.d.ts +4 -11
  56. package/esm/models/operations/sendchatcompletionrequest.js +5 -20
  57. package/esm/models/pipelinestage.d.ts +21 -0
  58. package/esm/models/pipelinestage.js +28 -0
  59. package/esm/models/pipelinestagetype.d.ts +21 -0
  60. package/esm/models/pipelinestagetype.js +20 -0
  61. package/esm/models/responsesstreamingresponse.d.ts +14 -0
  62. package/esm/models/responsesstreamingresponse.js +27 -0
  63. package/esm/models/routerattempt.d.ts +12 -0
  64. package/esm/models/routerattempt.js +17 -0
  65. package/esm/models/routerparams.d.ts +16 -0
  66. package/esm/models/routerparams.js +24 -0
  67. package/esm/models/routingstrategy.d.ts +16 -0
  68. package/esm/models/routingstrategy.js +18 -0
  69. package/jsr.json +1 -1
  70. package/package.json +6 -6
@@ -44,16 +44,11 @@ export type SendChatCompletionRequestRequest = {
44
44
  * @remarks
45
45
  */
46
46
  appCategories?: string | undefined;
47
- chatRequest: models.ChatRequest;
48
- };
49
- /**
50
- * Successful chat completion response
51
- */
52
- export type SendChatCompletionRequestResponseBody = {
53
47
  /**
54
- * Streaming chat completion chunk
48
+ * Opt-in to surface routing metadata on the response under `openrouter_metadata`. Defaults to `disabled`.
55
49
  */
56
- data: models.ChatStreamChunk;
50
+ xOpenRouterExperimentalMetadata?: models.MetadataLevel | undefined;
51
+ chatRequest: models.ChatRequest;
57
52
  };
58
53
  export type SendChatCompletionRequestResponse = models.ChatResult | EventStream<models.ChatStreamChunk>;
59
54
  /** @internal */
@@ -61,15 +56,13 @@ export type SendChatCompletionRequestRequest$Outbound = {
61
56
  "HTTP-Referer"?: string | undefined;
62
57
  appTitle?: string | undefined;
63
58
  appCategories?: string | undefined;
59
+ "X-OpenRouter-Experimental-Metadata"?: string | undefined;
64
60
  ChatRequest: models.ChatRequest$Outbound;
65
61
  };
66
62
  /** @internal */
67
63
  export declare const SendChatCompletionRequestRequest$outboundSchema: z.ZodType<SendChatCompletionRequestRequest$Outbound, SendChatCompletionRequestRequest>;
68
64
  export declare function sendChatCompletionRequestRequestToJSON(sendChatCompletionRequestRequest: SendChatCompletionRequestRequest): string;
69
65
  /** @internal */
70
- export declare const SendChatCompletionRequestResponseBody$inboundSchema: z.ZodType<SendChatCompletionRequestResponseBody, unknown>;
71
- export declare function sendChatCompletionRequestResponseBodyFromJSON(jsonString: string): SafeParseResult<SendChatCompletionRequestResponseBody, SDKValidationError>;
72
- /** @internal */
73
66
  export declare const SendChatCompletionRequestResponse$inboundSchema: z.ZodType<SendChatCompletionRequestResponse, unknown>;
74
67
  export declare function sendChatCompletionRequestResponseFromJSON(jsonString: string): SafeParseResult<SendChatCompletionRequestResponse, SDKValidationError>;
75
68
  //# sourceMappingURL=sendchatcompletionrequest.d.ts.map
@@ -12,10 +12,13 @@ export const SendChatCompletionRequestRequest$outboundSchema = z.object({
12
12
  httpReferer: z.string().optional(),
13
13
  appTitle: z.string().optional(),
14
14
  appCategories: z.string().optional(),
15
+ xOpenRouterExperimentalMetadata: models.MetadataLevel$outboundSchema
16
+ .optional(),
15
17
  chatRequest: models.ChatRequest$outboundSchema,
16
18
  }).transform((v) => {
17
19
  return remap$(v, {
18
20
  httpReferer: "HTTP-Referer",
21
+ xOpenRouterExperimentalMetadata: "X-OpenRouter-Experimental-Metadata",
19
22
  chatRequest: "ChatRequest",
20
23
  });
21
24
  });
@@ -23,25 +26,6 @@ export function sendChatCompletionRequestRequestToJSON(sendChatCompletionRequest
23
26
  return JSON.stringify(SendChatCompletionRequestRequest$outboundSchema.parse(sendChatCompletionRequestRequest));
24
27
  }
25
28
  /** @internal */
26
- export const SendChatCompletionRequestResponseBody$inboundSchema = z.object({
27
- data: z.string().transform((v, ctx) => {
28
- try {
29
- return JSON.parse(v);
30
- }
31
- catch (err) {
32
- ctx.addIssue({
33
- input: v,
34
- code: "custom",
35
- message: `malformed json: ${err}`,
36
- });
37
- return z.NEVER;
38
- }
39
- }).pipe(models.ChatStreamChunk$inboundSchema),
40
- });
41
- export function sendChatCompletionRequestResponseBodyFromJSON(jsonString) {
42
- return safeParse(jsonString, (x) => SendChatCompletionRequestResponseBody$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SendChatCompletionRequestResponseBody' from JSON`);
43
- }
44
- /** @internal */
45
29
  export const SendChatCompletionRequestResponse$inboundSchema = z.union([
46
30
  models.ChatResult$inboundSchema,
47
31
  z.custom(x => x instanceof ReadableStream)
@@ -51,7 +35,8 @@ export const SendChatCompletionRequestResponse$inboundSchema = z.union([
51
35
  return { done: true, value: undefined };
52
36
  return {
53
37
  done: false,
54
- value: z.lazy(() => SendChatCompletionRequestResponseBody$inboundSchema).parse(rawEvent)?.data,
38
+ value: models.ChatStreamingResponse$inboundSchema.parse(rawEvent)
39
+ ?.data,
55
40
  };
56
41
  });
57
42
  }),
@@ -0,0 +1,21 @@
1
+ import * as z from "zod/v4";
2
+ import { Result as SafeParseResult } from "../types/fp.js";
3
+ import { SDKValidationError } from "./errors/sdkvalidationerror.js";
4
+ import { PipelineStageType } from "./pipelinestagetype.js";
5
+ export type PipelineStage = {
6
+ costUsd?: number | null | undefined;
7
+ data?: {
8
+ [k: string]: any | null;
9
+ } | undefined;
10
+ guardrailId?: string | undefined;
11
+ guardrailScope?: string | undefined;
12
+ name: string;
13
+ /**
14
+ * Categorical kind of a pipeline stage. Multiple plugins can share a type (e.g. all guardrail-level plugins emit `guardrail`); the `name` field disambiguates which plugin emitted it.
15
+ */
16
+ type: PipelineStageType;
17
+ };
18
+ /** @internal */
19
+ export declare const PipelineStage$inboundSchema: z.ZodType<PipelineStage, unknown>;
20
+ export declare function pipelineStageFromJSON(jsonString: string): SafeParseResult<PipelineStage, SDKValidationError>;
21
+ //# sourceMappingURL=pipelinestage.d.ts.map
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: d737d34295bb
4
+ */
5
+ import * as z from "zod/v4";
6
+ import { remap as remap$ } from "../lib/primitives.js";
7
+ import { safeParse } from "../lib/schemas.js";
8
+ import { PipelineStageType$inboundSchema, } from "./pipelinestagetype.js";
9
+ /** @internal */
10
+ export const PipelineStage$inboundSchema = z
11
+ .object({
12
+ cost_usd: z.nullable(z.number()).optional(),
13
+ data: z.record(z.string(), z.nullable(z.any())).optional(),
14
+ guardrail_id: z.string().optional(),
15
+ guardrail_scope: z.string().optional(),
16
+ name: z.string(),
17
+ type: PipelineStageType$inboundSchema,
18
+ }).transform((v) => {
19
+ return remap$(v, {
20
+ "cost_usd": "costUsd",
21
+ "guardrail_id": "guardrailId",
22
+ "guardrail_scope": "guardrailScope",
23
+ });
24
+ });
25
+ export function pipelineStageFromJSON(jsonString) {
26
+ return safeParse(jsonString, (x) => PipelineStage$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'PipelineStage' from JSON`);
27
+ }
28
+ //# sourceMappingURL=pipelinestage.js.map
@@ -0,0 +1,21 @@
1
+ import * as z from "zod/v4";
2
+ import { OpenEnum } from "../types/enums.js";
3
+ /**
4
+ * Categorical kind of a pipeline stage. Multiple plugins can share a type (e.g. all guardrail-level plugins emit `guardrail`); the `name` field disambiguates which plugin emitted it.
5
+ */
6
+ export declare const PipelineStageType: {
7
+ readonly Router: "router";
8
+ readonly Guardrail: "guardrail";
9
+ readonly WebSearch: "web_search";
10
+ readonly FileParser: "file_parser";
11
+ readonly ServerTools: "server_tools";
12
+ readonly ResponseHealing: "response_healing";
13
+ readonly ContextCompression: "context_compression";
14
+ };
15
+ /**
16
+ * Categorical kind of a pipeline stage. Multiple plugins can share a type (e.g. all guardrail-level plugins emit `guardrail`); the `name` field disambiguates which plugin emitted it.
17
+ */
18
+ export type PipelineStageType = OpenEnum<typeof PipelineStageType>;
19
+ /** @internal */
20
+ export declare const PipelineStageType$inboundSchema: z.ZodType<PipelineStageType, unknown>;
21
+ //# sourceMappingURL=pipelinestagetype.d.ts.map
@@ -0,0 +1,20 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 5e7558516b45
4
+ */
5
+ import * as openEnums from "../types/enums.js";
6
+ /**
7
+ * Categorical kind of a pipeline stage. Multiple plugins can share a type (e.g. all guardrail-level plugins emit `guardrail`); the `name` field disambiguates which plugin emitted it.
8
+ */
9
+ export const PipelineStageType = {
10
+ Router: "router",
11
+ Guardrail: "guardrail",
12
+ WebSearch: "web_search",
13
+ FileParser: "file_parser",
14
+ ServerTools: "server_tools",
15
+ ResponseHealing: "response_healing",
16
+ ContextCompression: "context_compression",
17
+ };
18
+ /** @internal */
19
+ export const PipelineStageType$inboundSchema = openEnums.inboundSchema(PipelineStageType);
20
+ //# sourceMappingURL=pipelinestagetype.js.map
@@ -0,0 +1,14 @@
1
+ import * as z from "zod/v4";
2
+ import { Result as SafeParseResult } from "../types/fp.js";
3
+ import { SDKValidationError } from "./errors/sdkvalidationerror.js";
4
+ import { StreamEvents } from "./streamevents.js";
5
+ export type ResponsesStreamingResponse = {
6
+ /**
7
+ * Union of all possible event types emitted during response streaming
8
+ */
9
+ data: StreamEvents;
10
+ };
11
+ /** @internal */
12
+ export declare const ResponsesStreamingResponse$inboundSchema: z.ZodType<ResponsesStreamingResponse, unknown>;
13
+ export declare function responsesStreamingResponseFromJSON(jsonString: string): SafeParseResult<ResponsesStreamingResponse, SDKValidationError>;
14
+ //# sourceMappingURL=responsesstreamingresponse.d.ts.map
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 69284d63df45
4
+ */
5
+ import * as z from "zod/v4";
6
+ import { safeParse } from "../lib/schemas.js";
7
+ import { StreamEvents$inboundSchema } from "./streamevents.js";
8
+ /** @internal */
9
+ export const ResponsesStreamingResponse$inboundSchema = z.object({
10
+ data: z.string().transform((v, ctx) => {
11
+ try {
12
+ return JSON.parse(v);
13
+ }
14
+ catch (err) {
15
+ ctx.addIssue({
16
+ input: v,
17
+ code: "custom",
18
+ message: `malformed json: ${err}`,
19
+ });
20
+ return z.NEVER;
21
+ }
22
+ }).pipe(StreamEvents$inboundSchema),
23
+ });
24
+ export function responsesStreamingResponseFromJSON(jsonString) {
25
+ return safeParse(jsonString, (x) => ResponsesStreamingResponse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ResponsesStreamingResponse' from JSON`);
26
+ }
27
+ //# sourceMappingURL=responsesstreamingresponse.js.map
@@ -0,0 +1,12 @@
1
+ import * as z from "zod/v4";
2
+ import { Result as SafeParseResult } from "../types/fp.js";
3
+ import { SDKValidationError } from "./errors/sdkvalidationerror.js";
4
+ export type RouterAttempt = {
5
+ model: string;
6
+ provider: string;
7
+ status: number;
8
+ };
9
+ /** @internal */
10
+ export declare const RouterAttempt$inboundSchema: z.ZodType<RouterAttempt, unknown>;
11
+ export declare function routerAttemptFromJSON(jsonString: string): SafeParseResult<RouterAttempt, SDKValidationError>;
12
+ //# sourceMappingURL=routerattempt.d.ts.map
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 353df41da8e5
4
+ */
5
+ import * as z from "zod/v4";
6
+ import { safeParse } from "../lib/schemas.js";
7
+ /** @internal */
8
+ export const RouterAttempt$inboundSchema = z
9
+ .object({
10
+ model: z.string(),
11
+ provider: z.string(),
12
+ status: z.int(),
13
+ });
14
+ export function routerAttemptFromJSON(jsonString) {
15
+ return safeParse(jsonString, (x) => RouterAttempt$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'RouterAttempt' from JSON`);
16
+ }
17
+ //# sourceMappingURL=routerattempt.js.map
@@ -0,0 +1,16 @@
1
+ import * as z from "zod/v4";
2
+ import { Result as SafeParseResult } from "../types/fp.js";
3
+ import { SDKValidationError } from "./errors/sdkvalidationerror.js";
4
+ export type RouterParams = {
5
+ qualityFloor?: number | undefined;
6
+ sort?: string | undefined;
7
+ throughputFloor?: number | undefined;
8
+ versionGroup?: string | undefined;
9
+ additionalProperties?: {
10
+ [k: string]: any | null;
11
+ } | undefined;
12
+ };
13
+ /** @internal */
14
+ export declare const RouterParams$inboundSchema: z.ZodType<RouterParams, unknown>;
15
+ export declare function routerParamsFromJSON(jsonString: string): SafeParseResult<RouterParams, SDKValidationError>;
16
+ //# sourceMappingURL=routerparams.d.ts.map
@@ -0,0 +1,24 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 3b3282458763
4
+ */
5
+ import * as z from "zod/v4";
6
+ import { remap as remap$ } from "../lib/primitives.js";
7
+ import { collectExtraKeys as collectExtraKeys$, safeParse, } from "../lib/schemas.js";
8
+ /** @internal */
9
+ export const RouterParams$inboundSchema = collectExtraKeys$(z.object({
10
+ quality_floor: z.number().optional(),
11
+ sort: z.string().optional(),
12
+ throughput_floor: z.number().optional(),
13
+ version_group: z.string().optional(),
14
+ }).catchall(z.any()), "additionalProperties", true).transform((v) => {
15
+ return remap$(v, {
16
+ "quality_floor": "qualityFloor",
17
+ "throughput_floor": "throughputFloor",
18
+ "version_group": "versionGroup",
19
+ });
20
+ });
21
+ export function routerParamsFromJSON(jsonString) {
22
+ return safeParse(jsonString, (x) => RouterParams$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'RouterParams' from JSON`);
23
+ }
24
+ //# sourceMappingURL=routerparams.js.map
@@ -0,0 +1,16 @@
1
+ import * as z from "zod/v4";
2
+ import { OpenEnum } from "../types/enums.js";
3
+ export declare const RoutingStrategy: {
4
+ readonly Direct: "direct";
5
+ readonly Auto: "auto";
6
+ readonly Free: "free";
7
+ readonly Latest: "latest";
8
+ readonly Alias: "alias";
9
+ readonly Fallback: "fallback";
10
+ readonly Pareto: "pareto";
11
+ readonly Bodybuilder: "bodybuilder";
12
+ };
13
+ export type RoutingStrategy = OpenEnum<typeof RoutingStrategy>;
14
+ /** @internal */
15
+ export declare const RoutingStrategy$inboundSchema: z.ZodType<RoutingStrategy, unknown>;
16
+ //# sourceMappingURL=routingstrategy.d.ts.map
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ * @generated-id: 40bcbedca097
4
+ */
5
+ import * as openEnums from "../types/enums.js";
6
+ export const RoutingStrategy = {
7
+ Direct: "direct",
8
+ Auto: "auto",
9
+ Free: "free",
10
+ Latest: "latest",
11
+ Alias: "alias",
12
+ Fallback: "fallback",
13
+ Pareto: "pareto",
14
+ Bodybuilder: "bodybuilder",
15
+ };
16
+ /** @internal */
17
+ export const RoutingStrategy$inboundSchema = openEnums.inboundSchema(RoutingStrategy);
18
+ //# sourceMappingURL=routingstrategy.js.map
package/jsr.json CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  {
4
4
  "name": "@openrouter/sdk",
5
- "version": "0.12.29",
5
+ "version": "0.12.31",
6
6
  "exports": {
7
7
  ".": "./src/index.ts",
8
8
  "./models/errors": "./src/models/errors/index.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openrouter/sdk",
3
- "version": "0.12.29",
3
+ "version": "0.12.31",
4
4
  "author": "OpenRouter",
5
5
  "description": "The OpenRouter TypeScript SDK is a type-safe toolkit for building AI applications with access to 300+ language models through a unified API.",
6
6
  "keywords": [
@@ -69,14 +69,14 @@
69
69
  "lint": "eslint --cache --max-warnings=0 src",
70
70
  "build": "tsc",
71
71
  "prepublishOnly": "npm run build",
72
- "compile": "tsc",
73
- "postinstall": "node scripts/check-types.js || true",
74
72
  "prepare": "npm run build",
75
- "test:transit": "exit 0",
76
- "test:watch": "vitest --watch --project unit",
77
73
  "test": "vitest --run --project unit",
78
- "test:e2e": "vitest --run --project e2e",
74
+ "test:watch": "vitest --watch --project unit",
79
75
  "typecheck": "tsc --noEmit",
76
+ "compile": "tsc",
77
+ "postinstall": "node scripts/check-types.js || true",
78
+ "test:e2e": "vitest --run --project e2e",
79
+ "test:transit": "exit 0",
80
80
  "typecheck:transit": "exit 0"
81
81
  },
82
82
  "peerDependencies": {},