Responses - Python SDK

Responses method reference

(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

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 api_key=os.getenv("OPENROUTER_API_KEY", ""),
6) as open_router:
7
8 res = open_router.beta.responses.send(input=[
9 {
10 "type": "message",
11 "role": "user",
12 "content": "Hello, how are you?",
13 },
14 ], metadata={
15 "user_id": "123",
16 "session_id": "abc-def-ghi",
17 }, tools=[
18 {
19 "type": "function",
20 "name": "get_current_weather",
21 "description": "Get the current weather in a given location",
22 "parameters": {
23 "type": "object",
24 "properties": {
25 "location": {
26 "type": "string",
27 },
28 },
29 },
30 },
31 ], model="anthropic/claude-4.5-sonnet-20250929", text={
32 "format_": {
33 "type": "text",
34 },
35 "verbosity": "medium",
36 }, reasoning={
37 "summary": "auto",
38 "enabled": True,
39 }, temperature=0.7, top_p=0.9, prompt={
40 "id": "<id>",
41 "variables": {
42 "key": {
43 "type": "input_text",
44 "text": "Hello, how can I help you?",
45 },
46 },
47 }, service_tier="auto", truncation="auto", stream=False, provider={
48 "data_collection": "allow",
49 "zdr": True,
50 "enforce_distillable_text": True,
51 "order": [
52 "OpenAI",
53 ],
54 "only": [
55 "OpenAI",
56 ],
57 "ignore": [
58 "OpenAI",
59 ],
60 "quantizations": None,
61 "sort": "price",
62 })
63
64 with res as event_stream:
65 for event in event_stream:
66 # handle event
67 print(event, flush=True)

Parameters

ParameterTypeRequiredDescriptionExample
inputOptional[components.OpenResponsesInput]Input for a response request - can be a string or array of items[
{"role": "user","content": "What is the weather today?"}
]
instructionsOptionalNullable[str]N/A
metadataDict[str, str]Metadata key-value pairs for the request. Keys must be ≤64 characters and cannot contain brackets. Values must be ≤512 characters. Maximum 16 pairs allowed.{"user_id": "123","session_id": "abc-def-ghi"}
toolsList[components.OpenResponsesRequestToolUnion]N/A
tool_choiceOptional[components.OpenAIResponsesToolChoiceUnion]N/A
parallel_tool_callsOptionalNullable[bool]N/A
modelOptional[str]N/A
modelsList[str]N/A
textOptional[components.OpenResponsesResponseText]Text output configuration including format and verbosity{"format": {"type": "text"},
“verbosity”: “medium”
}
reasoningOptionalNullable[components.OpenResponsesReasoningConfig]Configuration for reasoning mode in the response{"summary": "auto","enabled": true}
max_output_tokensOptionalNullable[float]N/A
temperatureOptionalNullable[float]N/A
top_pOptionalNullable[float]N/A
top_kOptional[float]N/A
prompt_cache_keyOptionalNullable[str]N/A
previous_response_idOptionalNullable[str]N/A
promptOptionalNullable[components.OpenAIResponsesPrompt]N/A
includeList[components.OpenAIResponsesIncludable]N/A
backgroundOptionalNullable[bool]N/A
safety_identifierOptionalNullable[str]N/A
storeOptionalNullable[bool]N/A
service_tierOptionalNullable[components.ServiceTier]N/Aauto
truncationOptionalNullable[components.Truncation]N/Aauto
streamOptional[bool]N/A
providerOptionalNullable[components.Provider]When multiple model providers are available, optionally indicate your routing preference.
pluginsList[components.Plugin]Plugins you want to enable for this request, including their settings.
userOptional[str]A unique identifier representing your end-user, which helps distinguish between different users of your app. This allows your app to identify specific users in case of abuse reports, preventing your entire app from being affected by the actions of individual users. Maximum of 128 characters.
retriesOptional[utils.RetryConfig]Configuration to override the default retry behavior of the client.

Response

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*/*