Responses - TypeScript SDK

Responses method reference

The TypeScript SDK and docs are currently in beta. Report issues on GitHub.

(beta.responses)

Overview

beta.responses endpoints

Available Operations

  • send - Create a response

send

Creates a streaming or non-streaming response using OpenResponses API format

Example Usage

1import { OpenRouter } from "@openrouter/sdk";
2
3const openRouter = new OpenRouter({
4 apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
5});
6
7async function run() {
8 const result = await openRouter.beta.responses.send({});
9
10 console.log(result);
11}
12
13run();

Standalone function

The standalone function version of this method:

1import { OpenRouterCore } from "@openrouter/sdk/core.js";
2import { betaResponsesSend } from "@openrouter/sdk/funcs/betaResponsesSend.js";
3
4// Use `OpenRouterCore` for best tree-shaking performance.
5// You can create one instance of it to use across an application.
6const openRouter = new OpenRouterCore({
7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "",
8});
9
10async function run() {
11 const res = await betaResponsesSend(openRouter, {});
12 if (res.ok) {
13 const { value: result } = res;
14 console.log(result);
15 } else {
16 console.log("betaResponsesSend failed:", res.error);
17 }
18}
19
20run();

React hooks and utilities

This method can be used in React components through the following hooks and associated utilities.

Check out this guide for information about each of the utilities below and how to get started using React hooks.

1import {
2 // Mutation hook for triggering the API call.
3 useBetaResponsesSendMutation
4} from "@openrouter/sdk/react-query/betaResponsesSend.js";

Parameters

ParameterTypeRequiredDescription
requestmodels.OpenResponsesRequest✔️The request object to use for the request.
optionsRequestOptionsUsed to set various options for making HTTP requests.
options.fetchOptionsRequestInitOptions that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retriesRetryConfigEnables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.CreateResponsesResponse>

Errors

Error TypeStatus CodeContent Type
errors.BadRequestResponseError400application/json
errors.UnauthorizedResponseError401application/json
errors.PaymentRequiredResponseError402application/json
errors.NotFoundResponseError404application/json
errors.RequestTimeoutResponseError408application/json
errors.PayloadTooLargeResponseError413application/json
errors.UnprocessableEntityResponseError422application/json
errors.TooManyRequestsResponseError429application/json
errors.InternalServerResponseError500application/json
errors.BadGatewayResponseError502application/json
errors.ServiceUnavailableResponseError503application/json
errors.EdgeNetworkTimeoutResponseError524application/json
errors.ProviderOverloadedResponseError529application/json
errors.OpenRouterDefaultError4XX, 5XX*/*