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

# Tạo phản hồi (OpenAI Phản hồi API)

> OpenAI Responses API, dùng để tạo phản hồi của mô hình.
Hỗ trợ các tính năng như hội thoại đa vòng, gọi công cụ, suy luận.

Bổ sung các trường hợp sử dụng tạo ảnh bất đồng bộ cho OpenAI Responses API. `background=true` dùng để gửi tác vụ nền, API tạo sẽ trả về ngay `status=queued` và `id` đầy đủ, sau đó dùng `id` này để gọi `GET /v1/responses/{response_id}` truy vấn kết quả.

## Quy trình tạo ảnh bất đồng bộ

1. Gọi `POST /v1/responses`, trong body của request truyền `tools=[{ "type": "image_generation" }]` và `background=true`.
2. Lưu lại toàn bộ `id` do API tạo trả về, ví dụ `resp_xxx`. Không cắt ngắn, viết lại hoặc chỉ lưu `metadata.task_id`.
3. Gọi `GET /v1/responses/{response_id}` để truy vấn cho đến khi `status=completed` hoặc `status=failed`.
4. Sau khi thành công, đọc `output[].url` để lấy liên kết ảnh.

### Ví dụ tạo tác vụ ảnh bất đồng bộ

```http
POST /v1/responses
Content-Type: application/json
```

```json
{
  "model": "gpt-image-2-2k",
  "input": "生成一张 2K 横屏产品海报，白色运动鞋，干净棚拍光线，高级商业摄影风格。",
  "stream": false,
  "tools": [
    {
      "type": "image_generation"
    }
  ],
  "background": true
}
```

Ví dụ phản hồi của API tạo:

```json
{
  "id": "resp_xxx",
  "created_at": 1780649146,
  "error": null,
  "incomplete_details": null,
  "instructions": null,
  "metadata": {
    "task_id": "010c31178d26436ca6194cde07931b33"
  },
  "model": "gpt-image-2-2k",
  "object": "response",
  "output": [],
  "parallel_tool_calls": true,
  "temperature": null,
  "tool_choice": null,
  "tools": null,
  "top_p": null,
  "max_output_tokens": null,
  "previous_response_id": null,
  "reasoning": null,
  "status": "queued",
  "text": null,
  "truncation": null,
  "usage": null,
  "user": null,
  "store": null
}
```

Các model được hỗ trợ: `gpt-image-2-2k`, `gpt-image-2-4k`, `nano-banana-pro`.



## OpenAPI

````yaml api-reference/vi/openapi.json POST /v1/responses
openapi: 3.0.0
info:
  title: Tài liệu tham khảo API của 出海营
  version: 1.0.0
  description: Public AI Gateway API Reference
servers:
  - url: https://api.aiid.edu.kg
security:
  - BearerAuth: []
tags:
  - name: Định dạng OpenAI (Chat)
  - name: Định dạng OpenAI (Responses)
  - name: Định dạng Gemini cho tạo ảnh
  - name: Tạo hình ảnhOpenAI định dạng DALL-E
  - name: Lấy danh sách mô hình
  - name: Tạo video HappyHorse và Wan
  - name: Định dạngKling tạo video
  - name: Định dạng Video Generation Omni và Veo
  - name: Tạo video Seedance
  - name: Định dạng tương thích Sora cho tạo video
  - name: Tạo video Vidu
  - name: Định dạng tác vụ tạo nhạc
paths:
  /v1/responses:
    post:
      tags:
        - Định dạng OpenAI (Responses)
      summary: Tạo phản hồi (OpenAI Phản hồi API)
      description: >-
        OpenAI Responses API, dùng để tạo phản hồi của mô hình.

        Hỗ trợ các tính năng như hội thoại đa vòng, gọi công cụ, suy luận.


        Bổ sung các trường hợp sử dụng tạo ảnh bất đồng bộ cho OpenAI Responses
        API. `background=true` dùng để gửi tác vụ nền, API tạo sẽ trả về ngay
        `status=queued` và `id` đầy đủ, sau đó dùng `id` này để gọi `GET
        /v1/responses/{response_id}` truy vấn kết quả.


        ## Quy trình tạo ảnh bất đồng bộ


        1. Gọi `POST /v1/responses`, trong body của request truyền `tools=[{
        "type": "image_generation" }]` và `background=true`.

        2. Lưu lại toàn bộ `id` do API tạo trả về, ví dụ `resp_xxx`. Không cắt
        ngắn, viết lại hoặc chỉ lưu `metadata.task_id`.

        3. Gọi `GET /v1/responses/{response_id}` để truy vấn cho đến khi
        `status=completed` hoặc `status=failed`.

        4. Sau khi thành công, đọc `output[].url` để lấy liên kết ảnh.


        ### Ví dụ tạo tác vụ ảnh bất đồng bộ


        ```http

        POST /v1/responses

        Content-Type: application/json

        ```


        ```json

        {
          "model": "gpt-image-2-2k",
          "input": "生成一张 2K 横屏产品海报，白色运动鞋，干净棚拍光线，高级商业摄影风格。",
          "stream": false,
          "tools": [
            {
              "type": "image_generation"
            }
          ],
          "background": true
        }

        ```


        Ví dụ phản hồi của API tạo:


        ```json

        {
          "id": "resp_xxx",
          "created_at": 1780649146,
          "error": null,
          "incomplete_details": null,
          "instructions": null,
          "metadata": {
            "task_id": "010c31178d26436ca6194cde07931b33"
          },
          "model": "gpt-image-2-2k",
          "object": "response",
          "output": [],
          "parallel_tool_calls": true,
          "temperature": null,
          "tool_choice": null,
          "tools": null,
          "top_p": null,
          "max_output_tokens": null,
          "previous_response_id": null,
          "reasoning": null,
          "status": "queued",
          "text": null,
          "truncation": null,
          "usage": null,
          "user": null,
          "store": null
        }

        ```


        Các model được hỗ trợ: `gpt-image-2-2k`, `gpt-image-2-4k`,
        `nano-banana-pro`.
      operationId: createResponse
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ResponsesRequest'
              properties: {}
            examples:
              responses_image_async:
                summary: Tạo ảnh không đồng bộ
                value:
                  model: gpt-image-2-2k
                  input: 生成一张 2K 横屏产品海报，白色运动鞋，干净棚拍光线，高级商业摄影风格。
                  stream: false
                  tools:
                    - type: image_generation
                  background: true
        required: true
      responses:
        '200':
          description: Phản hồi tạo thành công
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ResponsesResponse'
              examples:
                responses_image_async_queued:
                  summary: Phản hồi khi tạo không đồng bộ ảnh
                  value:
                    id: resp_xxx
                    created_at: 1780649146
                    error: null
                    incomplete_details: null
                    instructions: null
                    metadata:
                      task_id: 010c31178d26436ca6194cde07931b33
                    model: gpt-image-2-2k
                    object: response
                    output: []
                    parallel_tool_calls: true
                    temperature: null
                    tool_choice: null
                    tools: null
                    top_p: null
                    max_output_tokens: null
                    previous_response_id: null
                    reasoning: null
                    status: queued
                    text: null
                    truncation: null
                    usage: null
                    user: null
                    store: null
          headers: {}
      deprecated: false
      security:
        - BearerAuth: []
components:
  schemas:
    ResponsesRequest:
      type: object
      required:
        - model
      properties:
        model:
          type: string
        input:
          description: Nội dung nhập vào, có thể là một chuỗi hoặc một mảng các tin nhắn
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                properties: {}
        instructions:
          type: string
        max_output_tokens:
          type: integer
        temperature:
          type: number
        top_p:
          type: number
        stream:
          type: boolean
        tools:
          type: array
          items:
            type: object
            properties: {}
        tool_choice:
          oneOf:
            - type: string
            - type: object
              properties: {}
        reasoning:
          type: object
          properties:
            effort:
              type: string
              enum:
                - low
                - medium
                - high
            summary:
              type: string
        previous_response_id:
          type: string
        truncation:
          type: string
          enum:
            - auto
            - disabled
    ResponsesResponse:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
          example: response
        created_at:
          type: integer
        status:
          type: string
          enum:
            - completed
            - failed
            - in_progress
            - incomplete
        model:
          type: string
        output:
          type: array
          items:
            type: object
            properties:
              type:
                type: string
              id:
                type: string
              status:
                type: string
              role:
                type: string
              content:
                type: array
                items:
                  type: object
                  properties:
                    type:
                      type: string
                    text:
                      type: string
        usage:
          $ref: '#/components/schemas/Usage'
    Usage:
      type: object
      properties:
        prompt_tokens:
          type: integer
          description: Số lượng Token của lời nhắc
        completion_tokens:
          type: integer
          description: Số Token hoàn thiện
        total_tokens:
          type: integer
          description: Tổng số Token
        prompt_tokens_details:
          type: object
          properties:
            cached_tokens:
              type: integer
            text_tokens:
              type: integer
            audio_tokens:
              type: integer
            image_tokens:
              type: integer
        completion_tokens_details:
          type: object
          properties:
            text_tokens:
              type: integer
            audio_tokens:
              type: integer
            reasoning_tokens:
              type: integer
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: |-
        Sử dụng xác thực Bearer Token.
        Định dạng: `Authorization: Bearer sk-xxxxxx`

````