> ## Documentation Index
> Fetch the complete documentation index at: https://docs.baseten.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Responses

> Create OpenAI Responses API requests against Baseten Model APIs, including streaming, function tools, and structured outputs.

> [!TIP]
>
> Download the [OpenAPI schema](https://docs.baseten.co/reference/inference-api/responses-openapi-spec.json) for code generation and client libraries.

[Model APIs](https://app.baseten.co/model-apis/create) accept requests in the [OpenAI Responses API](https://platform.openai.com/docs/api-reference/responses) format at `https://inference.baseten.co/v1/responses`. Use it for the OpenAI Agents SDK and other clients built on the Responses API. Requests are [stateless](#requests-are-stateless): send the full conversation as `input` on every call.

## Call with the OpenAI SDK

Point the OpenAI client at Baseten and call `responses.create`:

**Python**

**To call a model with the Responses API**:

```python responses.py theme={"system"}
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://inference.baseten.co/v1",
    api_key=os.environ["BASETEN_API_KEY"],
)

response = client.responses.create(
    model="zai-org/GLM-5.3",
    instructions="Answer in three words.",
    input="What is the capital of France?",
)

print(response.output_text)
```

**JavaScript**

**To call a model with the Responses API**:

```javascript responses.mjs theme={"system"}
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://inference.baseten.co/v1",
  apiKey: process.env.BASETEN_API_KEY,
});

const response = await client.responses.create({
  model: "zai-org/GLM-5.3",
  instructions: "Answer in three words.",
  input: "What is the capital of France?",
});

console.log(response.output_text);
```

**cURL**

**To call a model with the Responses API**:

```bash Request theme={"system"}
curl https://inference.baseten.co/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $BASETEN_API_KEY" \
  -d '{
    "model": "zai-org/GLM-5.3",
    "instructions": "Answer in three words.",
    "input": "What is the capital of France?"
  }'
```

The remaining Python examples on this page reuse `client` from this section.

## Use with the OpenAI Agents SDK

Configure the Agents SDK to use the Responses API, then pass the model as an `OpenAIResponsesModel`. Agent model names are parsed as `<provider>/<model>` strings, so a Baseten slug such as `zai-org/GLM-5.3` fails with `Unknown prefix: zai-org` if you pass it as a string. Build the model object instead:

```python agent.py theme={"system"}
import asyncio
import os

from agents import Agent, Runner, set_default_openai_api, set_default_openai_client
from agents.models.openai_responses import OpenAIResponsesModel
from openai import AsyncOpenAI

client = AsyncOpenAI(
    base_url="https://inference.baseten.co/v1",
    api_key=os.environ["BASETEN_API_KEY"],
)

set_default_openai_client(client)
set_default_openai_api("responses")

MODEL = OpenAIResponsesModel(model="zai-org/GLM-5.3", openai_client=client)

agent = Agent(
    name="Assistant",
    model=MODEL,
    instructions="Answer in three words.",
)

result = asyncio.run(Runner.run(agent, "What is the capital of France?"))
print(result.final_output)
```

Tool calls, multi-turn runs, and streaming work through `Runner.run` and `Runner.run_streamed`.

## Requests are stateless

Baseten stores no response and exposes no retrieval endpoint, so a request can't refer to an earlier response. To continue a conversation, send the previous `output` back as part of `input`:

```python continue.py theme={"system"}
first = client.responses.create(model="zai-org/GLM-5.3", input="Name three countries in South America.")

second = client.responses.create(
    model="zai-org/GLM-5.3",
    input=[*first.output, {"role": "user", "content": "Which of those has the largest population?"}],
)
```

## Stream responses

Set `stream` to receive server-sent events. Each event carries a `type` and a `sequence_number`; token deltas arrive as `response.output_text.delta`, and the response closes with `response.completed`:

```python stream.py theme={"system"}
stream = client.responses.create(
    model="zai-org/GLM-5.3",
    input="Write a haiku about GPUs.",
    stream=True,
)

for event in stream:
    if event.type == "response.output_text.delta":
        print(event.delta, end="")
```

## Call function tools

Declare function tools in `tools`, then send the model's call and your function's result back as input items. A `function_call` item carries the arguments as a JSON string:

```python tools.py theme={"system"}
import json


def get_weather(city):
    # Replace with a call to your weather service.
    return {"city": city, "temperature_c": 18, "conditions": "cloudy"}


tools = [
    {
        "type": "function",
        "name": "get_weather",
        "description": "Get the current weather for a city.",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    }
]

messages = [{"role": "user", "content": "What is the weather in Paris?"}]
response = client.responses.create(model="zai-org/GLM-5.3", input=messages, tools=tools)

call = next(item for item in response.output if item.type == "function_call")
arguments = json.loads(call.arguments)
result = get_weather(**arguments)

messages = [
    *messages,
    call,
    {"type": "function_call_output", "call_id": call.call_id, "output": json.dumps(result)},
]
final = client.responses.create(model="zai-org/GLM-5.3", input=messages, tools=tools)
print(final.output_text)
```

## Return structured output

Set `text.format` to a JSON schema to constrain the message text:

```python structured.py theme={"system"}
response = client.responses.create(
    model="zai-org/GLM-5.3",
    input="Classify this review: the fans are loud but the screen is gorgeous.",
    text={
        "format": {
            "type": "json_schema",
            "name": "sentiment",
            "schema": {
                "type": "object",
                "properties": {
                    "sentiment": {"type": "string", "enum": ["positive", "negative", "mixed"]},
                    "aspects": {"type": "array", "items": {"type": "string"}},
                },
                "required": ["sentiment", "aspects"],
                "additionalProperties": False,
            },
            "strict": True,
        }
    },
)

print(response.output_text)
```

## Unsupported fields

Baseten serves Responses statelessly, so fields that depend on stored state aren't supported. The endpoint rejects requests that set `previous_response_id`, `conversation`, `background`, or `prompt` with HTTP `501`; send the full prompt and prior turns as `input` instead.

The endpoint accepts `store`, but there is no `GET /v1/responses/{id}` to retrieve a stored response. Store the response yourself if you need to refer to it later.


## OpenAPI

````yaml reference/inference-api/responses-openapi-spec.json post /v1/responses
openapi: 3.0.0
info:
  title: Baseten Responses
  version: 1.0.0
  description: >-
    OpenAI Responses-compatible API for Baseten Model APIs. Requests are
    stateless: send the full conversation as `input` on every call.
servers: []
security: []
paths:
  /v1/responses:
    post:
      summary: Create a response
      description: >-
        Creates a model response from an input string or a list of input items.
        Requests are stateless: Baseten stores no response, so send prior turns
        back as input rather than referring to an earlier response.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                model:
                  type: string
                  description: Model slug, such as `zai-org/GLM-5.3`.
                input:
                  description: A prompt string, or a list of input items.
                  oneOf:
                    - type: string
                    - type: array
                      items:
                        type: object
                        properties:
                          role:
                            type: string
                            enum:
                              - user
                              - assistant
                              - system
                              - developer
                          content:
                            oneOf:
                              - type: string
                              - type: array
                                items:
                                  type: object
                                  properties:
                                    type:
                                      type: string
                                      enum:
                                        - input_text
                                        - output_text
                                    text:
                                      type: string
                                  required:
                                    - type
                                    - text
                        required:
                          - role
                          - content
                instructions:
                  type: string
                  description: System-level instructions for the request.
                max_output_tokens:
                  type: integer
                  minimum: 1
                  description: Upper bound on generated tokens, including reasoning tokens.
                temperature:
                  type: number
                  format: float
                  default: 1
                  minimum: 0
                  maximum: 2
                  description: Sampling temperature, from 0 to 2.
                top_p:
                  type: number
                  format: float
                  default: 1
                  minimum: 0
                  maximum: 1
                  description: Nucleus sampling threshold, from 0 to 1.
                stream:
                  type: boolean
                  default: false
                  description: >-
                    Stream server-sent events instead of returning one JSON
                    object.
                tools:
                  type: array
                  description: Function tools the model can call.
                  items:
                    type: object
                    properties:
                      type:
                        type: string
                        enum:
                          - function
                      name:
                        type: string
                      description:
                        type: string
                      parameters:
                        type: object
                        description: JSON Schema for the function arguments.
                    required:
                      - type
                      - name
                      - parameters
                tool_choice:
                  description: >-
                    Whether the model calls a tool. `auto` lets the model
                    decide, `required` forces a call, `none` forbids one.
                  oneOf:
                    - type: string
                      enum:
                        - auto
                        - required
                        - none
                    - type: object
                      properties:
                        type:
                          type: string
                          enum:
                            - function
                        name:
                          type: string
                      required:
                        - type
                        - name
                parallel_tool_calls:
                  type: boolean
                  default: true
                  description: >-
                    Lets the model emit more than one function call in a
                    response.
                text:
                  type: object
                  description: Output format for the message text.
                  properties:
                    format:
                      oneOf:
                        - type: object
                          properties:
                            type:
                              type: string
                              enum:
                                - text
                          required:
                            - type
                        - type: object
                          properties:
                            type:
                              type: string
                              enum:
                                - json_schema
                            name:
                              type: string
                            schema:
                              type: object
                            strict:
                              type: boolean
                          required:
                            - type
                            - name
                            - schema
                reasoning:
                  type: object
                  description: Reasoning settings for models that expose them.
                  properties:
                    effort:
                      type: string
                      enum:
                        - minimal
                        - low
                        - medium
                        - high
                metadata:
                  type: object
                  description: Up to 16 key-value pairs, echoed back on the response.
                  additionalProperties:
                    type: string
                truncation:
                  type: string
                  enum:
                    - auto
                    - disabled
                  default: disabled
                  description: '`auto` or `disabled`.'
              required:
                - model
                - input
      responses:
        '200':
          description: >-
            The completed response, or a server-sent event stream when `stream`
            is true.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    description: Response identifier, prefixed `resp_`.
                  object:
                    type: string
                    enum:
                      - response
                  created_at:
                    type: integer
                  completed_at:
                    type: integer
                    nullable: true
                  status:
                    type: string
                    enum:
                      - completed
                      - incomplete
                      - failed
                      - in_progress
                  model:
                    type: string
                  output:
                    type: array
                    description: Output items in the order the model produced them.
                    items:
                      oneOf:
                        - type: object
                          properties:
                            type:
                              type: string
                              enum:
                                - message
                            id:
                              type: string
                            status:
                              type: string
                            role:
                              type: string
                              enum:
                                - assistant
                            content:
                              type: array
                              items:
                                type: object
                                properties:
                                  type:
                                    type: string
                                    enum:
                                      - output_text
                                  text:
                                    type: string
                                  annotations:
                                    type: array
                                    items:
                                      type: object
                                required:
                                  - type
                                  - text
                          required:
                            - type
                            - id
                            - role
                            - content
                        - type: object
                          properties:
                            type:
                              type: string
                              enum:
                                - reasoning
                            id:
                              type: string
                            summary:
                              type: array
                              items:
                                type: object
                            content:
                              type: array
                              items:
                                type: object
                                properties:
                                  type:
                                    type: string
                                    enum:
                                      - reasoning_text
                                  text:
                                    type: string
                                required:
                                  - type
                                  - text
                          required:
                            - type
                            - id
                        - type: object
                          properties:
                            type:
                              type: string
                              enum:
                                - function_call
                            id:
                              type: string
                            call_id:
                              type: string
                            name:
                              type: string
                            arguments:
                              type: string
                              description: >-
                                The function arguments, encoded as a JSON
                                string.
                          required:
                            - type
                            - id
                            - call_id
                            - name
                            - arguments
                  usage:
                    type: object
                    nullable: true
                    properties:
                      input_tokens:
                        type: integer
                      input_tokens_details:
                        type: object
                        properties:
                          cached_tokens:
                            type: integer
                          cache_write_tokens:
                            type: integer
                      output_tokens:
                        type: integer
                      output_tokens_details:
                        type: object
                        properties:
                          reasoning_tokens:
                            type: integer
                      total_tokens:
                        type: integer
                  incomplete_details:
                    type: object
                    nullable: true
                    properties:
                      reason:
                        type: string
                        description: >-
                          Why generation stopped early, such as
                          `max_output_tokens`.
                  error:
                    type: object
                    nullable: true
                  metadata:
                    type: object
                    additionalProperties:
                      type: string
                  instructions:
                    type: string
                    nullable: true
                  max_output_tokens:
                    type: integer
                    nullable: true
                  parallel_tool_calls:
                    type: boolean
                  temperature:
                    type: number
                    format: float
                  top_p:
                    type: number
                    format: float
                  tool_choice:
                    type: string
                  tools:
                    type: array
                    items:
                      type: object
                  truncation:
                    type: string
                  service_tier:
                    type: string
                  text:
                    type: object
                  reasoning:
                    type: object
                    nullable: true
                required:
                  - id
                  - object
                  - created_at
                  - status
                  - model
                  - output
            text/event-stream:
              schema:
                type: string
                description: >-
                  Server-sent events. Each event carries a `type`, a
                  `sequence_number`, and a payload, starting with
                  `response.created` and ending with `response.completed`,
                  `response.incomplete`, or `response.failed`.
        '400':
          description: The request was rejected.
          content:
            application/json:
              schema:
                type: object

````