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

# Responses

> Send input to an AI model and receive a response.

One endpoint for every model. Pass text or a document as `input`; what comes back depends on the model: generated text, a classification, extracted fields, redacted output, and more. The `input` and `output` shapes vary by model, so open a [model page](https://docs.herogpu.com/api-reference/models.md) for a prefilled playground. For the `messages`-style route, see [Chat completions](https://docs.herogpu.com/api-reference/chat-completions.md).

Install the official SDK from [npm](https://www.npmjs.com/package/zerogpu-api) or [PyPI](https://pypi.org/project/zerogpu-api/) (`pip install zerogpu-api`). Source: [zerogpu/SDK](https://github.com/zerogpu/SDK). Handle errors the same way as [API error codes](https://docs.herogpu.com/docs/production-patterns.md#handle-status-codes-explicitly).

## Authentication

Send your API key in the `x-api-key` header or, OpenAI-compatible, as `Authorization: Bearer <key>`. The `x-project-id` header is optional; send it only to scope a request to a specific project. See the [Quickstart](https://docs.herogpu.com/docs/quickstart.md#1-grab-your-credentials) for both forms in each language.

## Streaming

Set `"stream": true` to receive the response as server-sent events (`text/event-stream`) instead of one JSON body. Pass `-N` so curl prints each event as it arrives:

```bash cURL theme={null}
curl -N https://api.herogpu.com/v1/responses \
  -H "content-type: application/json" \
  -H "x-api-key: $HEROGPU_API_KEY" \
  -d '{
    "model": "gpt-4.1-mini",
    "input": "Write one sentence about the sea.",
    "stream": true
  }'
```

Each event is a `data:` line holding a JSON object with a `type` and a `sequence_number`:

```text theme={null}
data: {"type":"response.created","response":{"id":"resp_abc123","object":"response","status":"in_progress","output":[],...},"sequence_number":0}

data: {"type":"response.output_text.delta","item_id":"msg_abc123","output_index":0,"content_index":0,"delta":"The sea","sequence_number":4}

data: {"type":"response.output_text.delta","item_id":"msg_abc123","output_index":0,"content_index":0,"delta":" hums","sequence_number":5}

data: {"type":"response.completed","response":{"id":"resp_abc123","object":"response","status":"completed","output":[...],"usage":{...}},"sequence_number":17}

data: [DONE]
```

Events arrive in this order:

| Event | Sent when |
| - | - |
| `response.created`, `response.in_progress` | The response starts. `response` holds the response object, with an empty `output`. |
| `response.output_item.added` | An output item starts. `item` is a `message` or a `function_call`. |
| `response.content_part.added` | A content part of a message starts. |
| `response.output_text.delta` | The next chunk of text, in `delta`. Concatenate the deltas to build the text. |
| `response.output_text.done` | The content part is complete. `text` holds the full text. |
| `response.function_call_arguments.delta` | The next chunk of a tool call's arguments, in `delta`. |
| `response.function_call_arguments.done` | The tool call's arguments are complete. `arguments` holds the full JSON string. |
| `response.content_part.done`, `response.output_item.done` | The content part or output item is complete. |
| `response.completed` | The response is complete. `response` holds the full `output` and `usage`. |

Reasoning models also send `response.reasoning_text.delta` or `response.reasoning_summary_text.delta` events before the answer. Most models end the stream with `data: [DONE]`; treat `response.completed` as the end of the response and ignore `[DONE]`. Task models (classifiers and extractors) don't stream and return `400` with code `stream_not_supported`. Each [model page](https://docs.herogpu.com/api-reference/models.md) says whether the model supports streaming.

## Tool calling

Pass function definitions in `tools`. Each tool has a `type` of `function`, a `name`, a `description`, and its arguments as a JSON Schema in `parameters`:

```bash cURL theme={null}
curl https://api.herogpu.com/v1/responses \
  -H "content-type: application/json" \
  -H "x-api-key: $HEROGPU_API_KEY" \
  -d '{
    "model": "gpt-4.1-mini",
    "input": "What is the weather in Paris right now?",
    "tools": [
      {
        "type": "function",
        "name": "get_weather",
        "description": "Get the current weather for a city.",
        "parameters": {
          "type": "object",
          "properties": {
            "city": { "type": "string", "description": "City name" }
          },
          "required": ["city"]
        }
      }
    ]
  }'
```

When the model calls a tool, `output` contains a `function_call` item. `arguments` is a JSON-encoded string, so parse it before use:

```json theme={null}
{
  "id": "resp_abc123",
  "object": "response",
  "status": "completed",
  "model": "gpt-4.1-mini",
  "output": [
    {
      "type": "function_call",
      "id": "fc_abc123",
      "call_id": "call_S4s5bz8VtacSuLONhiOHriD7",
      "name": "get_weather",
      "arguments": "{\"city\":\"Paris\"}",
      "status": "completed"
    }
  ],
  "usage": { "input_tokens": 67, "output_tokens": 15, "total_tokens": 82 }
}
```

Some models return an empty `message` item before the `function_call`, so find the call by its `type` rather than by position. Run the function yourself, then send the result back. Pass `input` as an array with the original message, the `function_call` item, and a `function_call_output` item with the same `call_id`, and include `tools` again:

```bash cURL theme={null}
curl https://api.herogpu.com/v1/responses \
  -H "content-type: application/json" \
  -H "x-api-key: $HEROGPU_API_KEY" \
  -d '{
    "model": "gpt-4.1-mini",
    "input": [
      { "role": "user", "content": "What is the weather in Paris right now?" },
      {
        "type": "function_call",
        "call_id": "call_S4s5bz8VtacSuLONhiOHriD7",
        "name": "get_weather",
        "arguments": "{\"city\":\"Paris\"}"
      },
      {
        "type": "function_call_output",
        "call_id": "call_S4s5bz8VtacSuLONhiOHriD7",
        "output": "{\"city\": \"Paris\", \"temperature_c\": 18, \"conditions\": \"light rain\"}"
      }
    ],
    "tools": [
      {
        "type": "function",
        "name": "get_weather",
        "description": "Get the current weather for a city.",
        "parameters": {
          "type": "object",
          "properties": {
            "city": { "type": "string", "description": "City name" }
          },
          "required": ["city"]
        }
      }
    ]
  }'
```

The model answers with a `message` that uses the result, for example "The current weather in Paris is 18°C with light rain." With `"stream": true`, a tool call arrives as `response.function_call_arguments.delta` events followed by `response.function_call_arguments.done`. Models without tool support return `400` with code `tools_not_supported`; each [model page](https://docs.herogpu.com/api-reference/models.md) says whether the model supports tool calling.


## OpenAPI

````yaml api-reference/openapi/zerogpu.openapi.json POST /responses
openapi: 3.1.0
info:
  title: Herogpu API
  version: '1.0'
  description: >-
    REST API for herogpu model inference: `POST /v1/responses` and `POST
    /v1/chat/completions` (model-dependent).

    Authenticate every request with the `x-api-key` header or,
    OpenAI-compatible, `Authorization: Bearer <key>`. The `x-project-id` header
    is optional.

    Documentation: https://docs.herogpu.com


    **Per-model playgrounds** are listed on [Model
    playgrounds](/api-reference/models) with request examples for each model's
    use cases.

    These endpoint pages show a generic shape only.
servers:
  - url: https://api.herogpu.com/v1
    description: Production
security:
  - ApiKey: []
  - BearerAuth: []
paths:
  /responses:
    post:
      tags:
        - Responses
      summary: Create response
      operationId: createResponse
      parameters:
        - name: x-project-id
          in: header
          required: false
          schema:
            type: string
          description: >-
            Optional project identifier. Scopes the request to a specific
            project when provided.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateResponseRequest'
            examples:
              default:
                summary: Text input
                value:
                  model: llama-3.1-8b-instruct-fast
                  input: >-
                    NASA announced that its Artemis III mission is now scheduled
                    for late 2026, marking the first time astronauts will land
                    on the lunar surface since Apollo 17 in 1972. The mission
                    will send a crew of four to the Moon aboard the Orion
                    spacecraft, with two astronauts descending to the south pole
                    using SpaceX Starship as a lunar lander. Scientists are
                    particularly excited about exploring permanently shadowed
                    craters that may contain water ice, which could be critical
                    for sustaining long-term human presence on the Moon.
              streaming:
                summary: Streaming
                value:
                  model: gpt-4.1-mini
                  input: Write one sentence about the sea.
                  stream: true
              tools:
                summary: Tool calling
                value:
                  model: gpt-4.1-mini
                  input: What is the weather in Paris right now?
                  tools:
                    - type: function
                      name: get_weather
                      description: Get the current weather for a city.
                      parameters:
                        type: object
                        properties:
                          city:
                            type: string
                            description: City name
                        required:
                          - city
      responses:
        '200':
          description: >-
            Success. A JSON response object, or a stream of server-sent events
            when `stream` is `true`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Response'
              examples:
                default:
                  summary: Text response
                  value:
                    id: resp_abc123
                    object: response
                    created: 1710000000
                    model: llama-3.1-8b-instruct-fast
                    output:
                      - type: message
                        role: assistant
                        content:
                          - type: output_text
                            text: >-
                              Artemis III, slated for late 2026, will return
                              astronauts to the Moon for the first time since
                              1972, landing two crew at the south pole to study
                              shadowed craters that may hold water ice.
                    usage:
                      input_tokens: 112
                      output_tokens: 44
                      total_tokens: 156
                tool_call:
                  summary: Tool call
                  value:
                    id: resp_abc123
                    object: response
                    status: completed
                    model: gpt-4.1-mini
                    output:
                      - type: function_call
                        id: fc_abc123
                        call_id: call_S4s5bz8VtacSuLONhiOHriD7
                        name: get_weather
                        arguments: '{"city":"Paris"}'
                        status: completed
                    usage:
                      input_tokens: 67
                      output_tokens: 15
                      total_tokens: 82
            text/event-stream:
              schema:
                $ref: '#/components/schemas/ResponseStreamEvent'
              example:
                type: response.output_text.delta
                item_id: msg_abc123
                output_index: 0
                content_index: 0
                delta: The sea
                sequence_number: 4
        '400':
          description: Bad request (invalid body)
        '401':
          description: Unauthorized (missing API key)
        '403':
          description: Forbidden (invalid API key or permissions)
        '420':
          description: Insufficient quota (insufficient_quota)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error:
                  code: insufficient_quota
                  message: You have insufficient quota to complete this request.
        '500':
          description: Internal server error
components:
  schemas:
    CreateResponseRequest:
      type: object
      required:
        - model
        - input
      properties:
        model:
          type: string
          description: >-
            Model identifier. Open a [model page](/api-reference/models) for a
            dedicated playground with the correct body for that model.
          enum:
            - llama-3.1-8b-instruct-fast
            - llama-3.2-3b-instruct-fast
            - qwen3-30b-a3b-fp8
            - llama-guard-4-12b
            - LFM2.5-1.2B-Instruct
            - LFM2.5-1.2B-Thinking
            - gpt-oss-120b
            - qwen3.6-35b-a3b
            - deepseek-v4.1-flash
            - glm-5.3-flash
            - gpt-5.4-nano
            - gpt-5.6-luna
            - gpt-6-luna
            - gpt-4.1-mini
            - deberta-v3-small
            - gliner2.5-base-v1
            - gliner2.5-multi-v1
            - gliner2.5-decide-v1
            - zlm-v1-iab-classify-edge
            - zlm-v1-signal-extract
            - zlm-v2-iab-classify-edge-enriched
            - zlm-v1-iab-domain-classifier
            - zlm-v1-tool-decisions
            - unlimited-ocr
          example: llama-3.1-8b-instruct-fast
        input:
          description: >-
            The text or document to send, as a plain string. To return a tool
            result, send an array of input items instead: the conversation so
            far, the model's `function_call` item, and a `function_call_output`
            item with the same `call_id`.
          oneOf:
            - type: string
              minLength: 1
              format: textarea
              maxLength: 131072
              title: Text
            - type: array
              title: Input items
              items:
                $ref: '#/components/schemas/InputItem'
        stream:
          type: boolean
          default: false
          description: >-
            If `true`, the response is sent as server-sent events
            (`text/event-stream`) instead of one JSON body. See
            [Streaming](/api-reference/responses#streaming) for the events.
            Supported on text-generation models; task models (classifiers,
            extractors) return `400` with code `stream_not_supported`.
        tools:
          type: array
          items:
            $ref: '#/components/schemas/FunctionTool'
          description: >-
            Function tools the model may call. When it calls one, `output`
            contains a `function_call` item; see [Tool
            calling](/api-reference/responses#tool-calling). Models without tool
            support return `400` with code `tools_not_supported`.
        text:
          type: object
          description: Response format configuration.
          properties:
            format:
              type: object
              properties:
                type:
                  type: string
                  description: Output format for the response, for example `text`.
                  example: text
        instructions:
          type: string
          description: >-
            Optional system-style instructions applied on top of `input`, for
            models that support them.
        metadata:
          type: object
          additionalProperties: true
          description: >-
            Optional model-specific parameters, passed through to the model. For
            example, the GLiNER2.5 models accept `usecase` together with
            `labels` or `schema`. See the relevant [model
            page](/api-reference/models) for supported keys.
    Response:
      type: object
      description: The generated model response.
      properties:
        id:
          type: string
          description: Unique identifier for the response.
          example: resp_abc123
        object:
          type: string
          description: Object type. Always `response`.
          example: response
        created:
          type: integer
          description: Unix timestamp (seconds) when the response was created.
          example: 1710000000
        model:
          type: string
          description: The model used for inference.
          example: llama-3.1-8b-instruct-fast
        output:
          type: array
          description: >-
            Output items produced by the model: `message` items, and a
            `function_call` item for each tool the model calls. Reasoning models
            may also return a `reasoning` item. Read items by `type`, not by
            position.
          items:
            oneOf:
              - $ref: '#/components/schemas/OutputMessage'
              - $ref: '#/components/schemas/FunctionCall'
        usage:
          $ref: '#/components/schemas/Usage'
    ResponseStreamEvent:
      type: object
      description: >-
        One server-sent event of a streamed response. Each event is sent as a
        `data:` line holding this JSON object; most models end the stream with
        `data: [DONE]`.
      required:
        - type
        - sequence_number
      properties:
        type:
          type: string
          description: Event type.
          enum:
            - response.created
            - response.in_progress
            - response.output_item.added
            - response.content_part.added
            - response.output_text.delta
            - response.output_text.done
            - response.content_part.done
            - response.function_call_arguments.delta
            - response.function_call_arguments.done
            - response.reasoning_text.delta
            - response.reasoning_text.done
            - response.reasoning_summary_text.delta
            - response.output_item.done
            - response.completed
        sequence_number:
          type: integer
          description: Position of the event in the stream, starting at 0.
        output_index:
          type: integer
          description: Index of the output item the event belongs to.
        item_id:
          type: string
          description: ID of the output item the event belongs to.
        delta:
          type: string
          description: 'On `*.delta` events: the next chunk of text or function arguments.'
        text:
          type: string
          description: 'On `response.output_text.done`: the full text of the content part.'
        arguments:
          type: string
          description: >-
            On `response.function_call_arguments.done`: the full JSON-encoded
            arguments.
        item:
          type: object
          description: >-
            On `response.output_item.added` and `.done`: the output item
            (`message` or `function_call`).
        response:
          $ref: '#/components/schemas/Response'
          description: >-
            On `response.created`, `response.in_progress` and
            `response.completed`: the response object. On `response.completed`
            it holds the full `output` and `usage`.
    ErrorResponse:
      type: object
      description: Error payload returned on a failed request.
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              description: Machine-readable error code, for example `insufficient_quota`.
              example: insufficient_quota
            message:
              type: string
              description: Human-readable description of the error.
              example: You have insufficient quota to complete this request.
    InputItem:
      description: One item of an array `input`.
      oneOf:
        - $ref: '#/components/schemas/InputMessage'
        - $ref: '#/components/schemas/FunctionCall'
        - $ref: '#/components/schemas/FunctionCallOutput'
    FunctionTool:
      type: object
      description: A function the model may call.
      required:
        - type
        - name
        - parameters
      properties:
        type:
          type: string
          enum:
            - function
          description: Always `function`.
        name:
          type: string
          description: Function name the model uses to call it.
          example: get_weather
        description:
          type: string
          description: >-
            What the function does. The model uses this to decide when to call
            it.
          example: Get the current weather for a city.
        parameters:
          type: object
          additionalProperties: true
          description: JSON Schema for the function's arguments.
    OutputMessage:
      type: object
      description: A single output item from the model.
      properties:
        type:
          type: string
          description: Output item type.
          example: message
        role:
          type: string
          description: Author of the output. Always `assistant`.
          example: assistant
        content:
          type: array
          description: Content parts that make up the message.
          items:
            type: object
            properties:
              type:
                type: string
                description: Content part type.
                example: output_text
              text:
                type: string
                description: The generated text.
                example: >-
                  Artemis III, slated for late 2026, will return astronauts to
                  the Moon for the first time since 1972.
    FunctionCall:
      type: object
      title: Function call
      description: >-
        A tool call made by the model. Returned in `output`; send it back
        unchanged in `input` together with its `function_call_output`.
      properties:
        type:
          type: string
          enum:
            - function_call
          description: Always `function_call`.
        id:
          type: string
          description: Output item ID.
        call_id:
          type: string
          description: ID that links this call to its `function_call_output`.
          example: call_S4s5bz8VtacSuLONhiOHriD7
        name:
          type: string
          description: Name of the function to call.
          example: get_weather
        arguments:
          type: string
          description: Arguments as a JSON-encoded string. Parse it before use.
          example: '{"city":"Paris"}'
        status:
          type: string
          description: Item status, for example `completed`.
          example: completed
    Usage:
      type: object
      description: Token usage statistics for the request.
      properties:
        input_tokens:
          type: integer
          description: Number of tokens in the input.
          example: 112
        output_tokens:
          type: integer
          description: Number of tokens generated.
          example: 44
        total_tokens:
          type: integer
          description: Total tokens consumed (input plus output).
          example: 156
    InputMessage:
      type: object
      title: Message
      required:
        - role
        - content
      properties:
        role:
          type: string
          description: Author of the message, for example `user`.
          example: user
        content:
          type: string
          description: Message text.
    FunctionCallOutput:
      type: object
      title: Function call output
      description: The result of a tool call, sent back to the model.
      required:
        - type
        - call_id
        - output
      properties:
        type:
          type: string
          enum:
            - function_call_output
          description: Always `function_call_output`.
        call_id:
          type: string
          description: The `call_id` of the `function_call` this answers.
        output:
          type: string
          description: The tool result as a string, for example JSON.
          example: '{"city": "Paris", "temperature_c": 18, "conditions": "light rain"}'
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Your herogpu API key. Create one in the dashboard under API keys. Send
        it on every request.
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        OpenAI-compatible: send your herogpu API key as `Authorization: Bearer
        <key>`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.