@openrouter/sdk 1.5.136 → 1.5.137

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.
@@ -0,0 +1,21 @@
1
+ import { OpenRouterCore } from "../core.js";
2
+ import { RequestOptions } from "../lib/sdks.js";
3
+ import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError } from "../models/errors/httpclienterrors.js";
4
+ import * as errors from "../models/errors/index.js";
5
+ import { OpenRouterError } from "../models/errors/openroutererror.js";
6
+ import { ResponseValidationError } from "../models/errors/responsevalidationerror.js";
7
+ import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
8
+ import * as operations from "../models/operations/index.js";
9
+ import { APIPromise } from "../types/async.js";
10
+ import { Result } from "../types/fp.js";
11
+ import { PageIterator } from "../types/operations.js";
12
+ /**
13
+ * Get batch results
14
+ *
15
+ * @remarks
16
+ * Returns a cursor-paginated page of normalized OpenRouter-format results for a finished batch. Pass the previous page's `next_cursor` as `cursor` to read the next page. Pages are stable across retries for the 30-day artifact retention window. See the [Batch API Quickstart](https://openrouter.ai/docs/batch-quickstart).
17
+ */
18
+ export declare function batchGetResults(client: OpenRouterCore, request: operations.GetBatchResultsRequest, options?: RequestOptions): APIPromise<PageIterator<Result<operations.GetBatchResultsResponse, errors.BatchPaymentRequiredResponseError | errors.BatchErrorResponse | OpenRouterError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError>, {
19
+ cursor: string;
20
+ }>>;
21
+ //# sourceMappingURL=batchGetResults.d.ts.map
@@ -0,0 +1,136 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+ import { encodeFormQuery, encodeSimple } from "../lib/encodings.js";
5
+ import { matchStatusCode } from "../lib/http.js";
6
+ import * as M from "../lib/matchers.js";
7
+ import { compactMap } from "../lib/primitives.js";
8
+ import { safeParse } from "../lib/schemas.js";
9
+ import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
10
+ import { pathToFunc } from "../lib/url.js";
11
+ import { BatchErrorResponse$inboundSchema as errors_BatchErrorResponse$inboundSchema } from "../models/errors/batcherrorresponse.js"; import { BatchPaymentRequiredResponseError$inboundSchema as errors_BatchPaymentRequiredResponseError$inboundSchema } from "../models/errors/batchpaymentrequiredresponseerror.js";
12
+ import { GetBatchResultsRequest$outboundSchema as operations_GetBatchResultsRequest$outboundSchema, GetBatchResultsResponse$inboundSchema as operations_GetBatchResultsResponse$inboundSchema } from "../models/operations/getbatchresults.js";
13
+ import { APIPromise } from "../types/async.js";
14
+ import { createPageIterator, haltIterator, } from "../types/operations.js";
15
+ /**
16
+ * Get batch results
17
+ *
18
+ * @remarks
19
+ * Returns a cursor-paginated page of normalized OpenRouter-format results for a finished batch. Pass the previous page's `next_cursor` as `cursor` to read the next page. Pages are stable across retries for the 30-day artifact retention window. See the [Batch API Quickstart](https://openrouter.ai/docs/batch-quickstart).
20
+ */
21
+ export function batchGetResults(client, request, options) {
22
+ return new APIPromise($do(client, request, options));
23
+ }
24
+ async function $do(client, request, options) {
25
+ const parsed = safeParse(request, (value) => operations_GetBatchResultsRequest$outboundSchema.parse(value), "Input validation failed");
26
+ if (!parsed.ok) {
27
+ return [haltIterator(parsed), { status: "invalid" }];
28
+ }
29
+ const payload = parsed.value;
30
+ const body = null;
31
+ const pathParams = {
32
+ id: encodeSimple("id", payload.id, {
33
+ explode: false,
34
+ charEncoding: "percent",
35
+ }),
36
+ };
37
+ const path = pathToFunc("/batches/{id}/results")(pathParams);
38
+ const query = encodeFormQuery({
39
+ "cursor": payload.cursor,
40
+ "limit": payload.limit,
41
+ });
42
+ const headers = new Headers(compactMap({
43
+ Accept: "application/json",
44
+ "HTTP-Referer": encodeSimple("HTTP-Referer", payload["HTTP-Referer"] ?? client._options.httpReferer, { explode: false, charEncoding: "none" }),
45
+ "X-OpenRouter-Categories": encodeSimple("X-OpenRouter-Categories", payload.appCategories ?? client._options.appCategories, { explode: false, charEncoding: "none" }),
46
+ "X-OpenRouter-Title": encodeSimple("X-OpenRouter-Title", payload.appTitle ?? client._options.appTitle, { explode: false, charEncoding: "none" }),
47
+ }));
48
+ const secConfig = await extractSecurity(client._options.apiKey);
49
+ const securityInput = secConfig == null ? {} : { apiKey: secConfig };
50
+ const requestSecurity = resolveGlobalSecurity(securityInput);
51
+ const context = {
52
+ options: client._options,
53
+ baseURL: options?.serverURL ?? client._baseURL ?? "",
54
+ operationID: "getBatchResults",
55
+ oAuth2Scopes: null,
56
+ resolvedSecurity: requestSecurity,
57
+ securitySource: client._options.apiKey,
58
+ retryConfig: options?.retries
59
+ || client._options.retryConfig
60
+ || {
61
+ strategy: "backoff",
62
+ backoff: {
63
+ initialInterval: 500,
64
+ maxInterval: 60000,
65
+ exponent: 1.5,
66
+ maxElapsedTime: 3600000,
67
+ },
68
+ retryConnectionErrors: true,
69
+ }
70
+ || { strategy: "none" },
71
+ retryCodes: options?.retryCodes || ["5XX"],
72
+ };
73
+ const requestRes = client._createRequest(context, {
74
+ security: requestSecurity,
75
+ method: "GET",
76
+ baseURL: options?.serverURL,
77
+ path: path,
78
+ headers: headers,
79
+ query: query,
80
+ body: body,
81
+ userAgent: client._options.userAgent,
82
+ timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
83
+ }, options);
84
+ if (!requestRes.ok) {
85
+ return [haltIterator(requestRes), { status: "invalid" }];
86
+ }
87
+ const req = requestRes.value;
88
+ const doResult = await client._do(req, {
89
+ context,
90
+ isErrorStatusCode: (statusCode) => matchStatusCode({ status: statusCode }, ["4XX", "5XX"]),
91
+ retryConfig: context.retryConfig,
92
+ retryCodes: context.retryCodes,
93
+ });
94
+ if (!doResult.ok) {
95
+ return [haltIterator(doResult), { status: "request-error", request: req }];
96
+ }
97
+ const response = doResult.value;
98
+ const responseFields = {
99
+ HttpMeta: { Response: response, Request: req },
100
+ };
101
+ const [result, raw] = await M.match(M.json(200, operations_GetBatchResultsResponse$inboundSchema, {
102
+ key: "Result",
103
+ }), M.jsonErr(402, errors_BatchPaymentRequiredResponseError$inboundSchema), M.jsonErr([400, 401, 404, 409, 410, 413, 429], errors_BatchErrorResponse$inboundSchema), M.jsonErr([500, 502], errors_BatchErrorResponse$inboundSchema), M.fail("4XX"), M.fail("5XX"))(response, req, { extraFields: responseFields });
104
+ if (!result.ok) {
105
+ return [haltIterator(result), {
106
+ status: "complete",
107
+ request: req,
108
+ response,
109
+ }];
110
+ }
111
+ const nextFunc = (responseData) => {
112
+ const nextCursor = responseData.next_cursor;
113
+ if (typeof nextCursor !== "string") {
114
+ return { next: () => null };
115
+ }
116
+ if (nextCursor.trim() === "") {
117
+ return { next: () => null };
118
+ }
119
+ const results = responseData.data;
120
+ if (!Array.isArray(results) || !results.length) {
121
+ return { next: () => null };
122
+ }
123
+ const nextVal = () => batchGetResults(client, {
124
+ ...request,
125
+ cursor: nextCursor,
126
+ }, options);
127
+ return { next: nextVal, "~next": { cursor: nextCursor } };
128
+ };
129
+ const page = { ...result, ...nextFunc(raw) };
130
+ return [{ ...page, ...createPageIterator(page, (v) => !v.ok) }, {
131
+ status: "complete",
132
+ request: req,
133
+ response,
134
+ }];
135
+ }
136
+ //# sourceMappingURL=batchGetResults.js.map
@@ -49,8 +49,8 @@ export declare function serverURLFromOptions(options: SDKOptions): URL | null;
49
49
  export declare const SDK_METADATA: {
50
50
  readonly language: "typescript";
51
51
  readonly openapiDocVersion: "1.0.0";
52
- readonly sdkVersion: "1.5.136";
52
+ readonly sdkVersion: "1.5.137";
53
53
  readonly genVersion: "2.960.8";
54
- readonly userAgent: "speakeasy-sdk/typescript 1.5.136 2.960.8 1.0.0 @openrouter/sdk";
54
+ readonly userAgent: "speakeasy-sdk/typescript 1.5.137 2.960.8 1.0.0 @openrouter/sdk";
55
55
  };
56
56
  //# sourceMappingURL=config.d.ts.map
package/esm/lib/config.js CHANGED
@@ -25,8 +25,8 @@ export function serverURLFromOptions(options) {
25
25
  export const SDK_METADATA = {
26
26
  language: "typescript",
27
27
  openapiDocVersion: "1.0.0",
28
- sdkVersion: "1.5.136",
28
+ sdkVersion: "1.5.137",
29
29
  genVersion: "2.960.8",
30
- userAgent: "speakeasy-sdk/typescript 1.5.136 2.960.8 1.0.0 @openrouter/sdk",
30
+ userAgent: "speakeasy-sdk/typescript 1.5.137 2.960.8 1.0.0 @openrouter/sdk",
31
31
  };
32
32
  //# sourceMappingURL=config.js.map