> ## 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`:

> [tab] 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)
> ```

> [tab] 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);
> ```

> [tab] 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. The SDK convenience property `output_text` collects text from `output` items; the raw JSON response contains `output`, not an `output_text` field. Check `status` before treating that text as a complete answer.

## 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. Keep the original input, append all response `output` items, then append the next user turn. Resend `instructions` on each request when you use them.

**To continue a conversation**:

```python continue.py theme={"system"}
messages = [{"role": "user", "content": "Name three countries in South America."}]
first = client.responses.create(model="zai-org/GLM-5.3", input=messages)
if first.status != "completed":
    raise RuntimeError(f"Response did not complete: {first.status}")

messages.extend(first.output)
messages.append({"role": "user", "content": "Which of those has the largest population?"})
second = client.responses.create(model="zai-org/GLM-5.3", input=messages)
if second.status != "completed":
    raise RuntimeError(f"Response did not complete: {second.status}")
print(second.output_text)
```

## Stream responses

Set `stream` to receive server-sent events. Text arrives as `response.output_text.delta`. The terminal response can be `response.completed`, `response.incomplete`, or `response.failed`; an `error` event or a connection that ends before a terminal response also needs error handling.

For a complete request and output, including terminal-status and interrupted-stream checks, see [Stream responses](https://docs.baseten.co/inference/streaming.md#enable-streaming) and choose **Responses**.

## Call function tools

Declare function tools in `tools`. Each `function_call` output item contains `name`, JSON-encoded `arguments`, and a `call_id`. Execute every call, preserve all output items, and append a `function_call_output` with the matching `call_id` for each result. Keep the earlier input turns too.

A response can contain no calls or several parallel calls. Check its status and any refusal before treating a response without calls as final text. The model may request more tools after receiving results, so continue until it returns a complete answer.

For the complete request, tool results, and continuation loop, see [Function calling](https://docs.baseten.co/inference/function-calling.md#call-the-model) and choose **Responses**.

## 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:
  - url: https://inference.baseten.co
    description: Baseten Model APIs
security:
  - BearerAuth: []
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 the full conversation as input items.
                    Include prior user messages, all response output items, and
                    a function_call_output for each application function call.
                  oneOf:
                    - type: string
                    - type: array
                      items:
                        oneOf:
                          - $ref: '#/components/schemas/InputMessage'
                          - $ref: '#/components/schemas/ReasoningItem'
                          - $ref: '#/components/schemas/FunctionCall'
                          - $ref: '#/components/schemas/FunctionCallOutput'
                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: >-
            A response, which can be completed, incomplete, or failed; or a
            server-sent event stream when stream is true. Inspect the outcome
            before using the output.
          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
components:
  schemas:
    InputMessage:
      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
        type:
          type: string
          enum:
            - message
      required:
        - role
        - content
    ReasoningItem:
      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
    FunctionCall:
      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
        - call_id
        - name
        - arguments
    FunctionCallOutput:
      type: object
      description: >-
        The result of an application function call. Match call_id to the
        function_call item and encode the result as a string.
      properties:
        type:
          type: string
          enum:
            - function_call_output
        call_id:
          type: string
        output:
          type: string
      required:
        - type
        - call_id
        - output
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: A Baseten API key.

````