# Responses API

> Trường của POST /v1/responses trên LLMoxy, lọc mặc định, và lần gọi stream thật của grok-4.6 với grok-4.7.

`POST https://llmoxy.com/v1/responses` nhận JSON. Header:

```txt
Authorization: Bearer <LLMOXY_API_KEY>
Content-Type: application/json
```

Cổng phân tích thân request theo một cấu trúc cố định. Request bị từ chối khi `model` rỗng, khi không có `input`, hoặc khi `max_output_tokens` lớn hơn 1.073.741.823. `background` không nằm trong cấu trúc này.

Khi không bật chuyển nguyên thân request, chỉ các trường trong bảng được giữ, và `service_tier`, `safety_identifier` cùng `stream_options.include_obfuscation` bị bỏ theo mặc định. `store` được giữ. Số có thể trống ghi `0` và `stream` ghi `false` vẫn được gửi. Giá trị boolean `false` trong `stream_options` bị bỏ khi dựng lại thân request. Trường ngoài bảng không được gửi.

## Trường request

| Trường | Kiểu | Bắt buộc | Cách cổng xử lý |
| --- | --- | --- | --- |
| `model` | string | có | ID mô hình không rỗng. |
| `input` | string hoặc array | có | Phải có mặt. Chuỗi được tính là một đoạn văn bản đầu vào. Phần tử mảng có thể kèm `role`. `content` dạng chuỗi được tính là văn bản. `content` dạng mảng nhận `input_text`, `input_image` và `input_file`. `image_url` và `file_url` có thể là chuỗi hoặc object có `url`. |
| `include` | JSON | không | Giữ nguyên. |
| `conversation` | JSON | không | Giữ nguyên. |
| `context_management` | JSON | không | Giữ nguyên. |
| `instructions` | JSON | không | Giữ nguyên. Dạng thường gặp là chuỗi. |
| `max_output_tokens` | number | không | Có thể trống. `0` tường minh được giữ. |
| `top_logprobs` | number | không | Có thể trống. `0` tường minh được giữ. |
| `metadata` | JSON | không | Giữ nguyên. |
| `parallel_tool_calls` | JSON | không | Giữ nguyên. `false` tường minh được giữ. |
| `previous_response_id` | string | không | Chuỗi rỗng bị bỏ. |
| `reasoning.effort` | string | không | Chuỗi rỗng bị bỏ. Cổng không kiểm tra giá trị. |
| `reasoning.summary` | string | không | Chuỗi rỗng bị bỏ. Cổng không kiểm tra giá trị. |
| `service_tier` | string | không | Mặc định bị bỏ. |
| `store` | JSON | không | Mặc định được giữ. `false` tường minh được giữ. |
| `prompt_cache_key` | JSON | không | Giữ nguyên. |
| `prompt_cache_retention` | JSON | không | Giữ nguyên. |
| `safety_identifier` | JSON | không | Mặc định bị bỏ. |
| `stream` | boolean | không | Vắng mặt nghĩa là request không stream. `false` tường minh được giữ. |
| `stream_options.include_usage` | boolean | không | Khi dựng lại, `false` bị bỏ. |
| `stream_options.include_obfuscation` | boolean | không | Mặc định bị bỏ. Khi dựng lại, `false` bị bỏ. |
| `temperature` | number | không | Có thể trống. `0` tường minh được giữ. |
| `text` | JSON | không | Giữ nguyên. |
| `tool_choice` | JSON | không | Giữ nguyên. |
| `tools` | JSON | không | Giữ nguyên. |
| `top_p` | number | không | Có thể trống. `0` tường minh được giữ. |
| `truncation` | JSON | không | Giữ nguyên. |
| `user` | JSON | không | Giữ nguyên. |
| `max_tool_calls` | number | không | Có thể trống. `0` tường minh được giữ. |
| `prompt` | JSON | không | Giữ nguyên. |
| `enable_thinking` | JSON | không | Giữ nguyên. |
| `preset` | JSON | không | Giữ nguyên. |

## grok-4.6 và grok-4.7

Ngày 2026-10-03, lệnh gọi stream tới `https://llmoxy.com/v1/responses` cho `grok-4.6` và `grok-4.7` đều trả HTTP 200 và cùng một dãy sự kiện.

| Mô hình | HTTP | `model` trong phản hồi | `status` | Văn bản | input / output / total |
| --- | --- | --- | --- | --- | --- |
| `grok-4.6` | 200 | `grok-4.6` | `completed` | `pong` | 212 / 98 / 310 |
| `grok-4.7` | 200 | `grok-4.7` | `completed` | `pong` | 1248 / 55 / 1303 |

Với `grok-4.6`, `input_tokens_details.cached_tokens` là 128 và `output_tokens_details.reasoning_tokens` là 97. Với `grok-4.7`, hai giá trị đó là 1152 và 54.

Văn bản nằm ở phần tử `output` có `type` là `message`, trong `content` có `type` là `output_text`, trường `text`. Cả hai mô hình đều phát trước một phần tử `type` là `reasoning`. Trong `response.completed`, `status` của phần tử reasoning đó vẫn là `in_progress`.

Request của hai mô hình này bật chuyển nguyên thân request, nên JSON tối thiểu ở mục sau được gửi đúng như client đã viết.

## Request tối thiểu đã thành công

Với `grok-4.6`, dùng cùng thân request và đổi `model` thành `grok-4.6`.

```bash
curl https://llmoxy.com/v1/responses \
  -H "Authorization: Bearer <LLMOXY_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-4.7",
    "input": "Reply with exactly: pong",
    "max_output_tokens": 64,
    "stream": true
  }'
```

`Content-Type` của phản hồi là `text/event-stream`. Mỗi sự kiện gồm một dòng `event:` và một dòng `data:`. Cổng chuyển nguyên JSON của sự kiện đã phân tích được, và tên sự kiện lấy từ `type`. Stream kết thúc bằng `response.completed` cuối cùng.

Hai mô hình phát cùng tên sự kiện theo thứ tự này:

`response.created`, `response.in_progress`, `response.output_item.added`, `response.reasoning_summary_part.added`, `response.reasoning_summary_text.delta`, `response.reasoning_summary_text.delta`, `response.reasoning_summary_text.done`, `response.reasoning_summary_part.done`, `response.output_item.done`, `response.output_item.added`, `response.content_part.added`, `response.output_text.delta`, `response.output_text.done`, `response.content_part.done`, `response.output_item.done`, `response.completed`.

Đoạn dưới là phản hồi `grok-4.7`. ID phản hồi và ID phần tử đã được đổi thành chỗ giữ chỗ. Các trường còn lại khớp với lần gọi đó.

```txt
event: response.created
data: {"type":"response.created","sequence_number":0,"response":{"object":"response","id":"resp_example","created_at":1791015238,"model":"grok-4.7","output":[],"status":"in_progress"},"output_index":0}

event: response.in_progress
data: {"type":"response.in_progress","sequence_number":1,"response":{"object":"response","id":"resp_example","created_at":1791015238,"model":"grok-4.7","output":[],"status":"in_progress"},"output_index":0}

event: response.output_item.added
data: {"type":"response.output_item.added","sequence_number":2,"output_index":0,"item":{"id":"item_reasoning","type":"reasoning","status":"in_progress","summary":[]}}

event: response.reasoning_summary_part.added
data: {"type":"response.reasoning_summary_part.added","sequence_number":3,"output_index":0,"item_id":"item_reasoning","part":{"type":"summary_text","text":""},"summary_index":0}

event: response.reasoning_summary_text.delta
data: {"type":"response.reasoning_summary_text.delta","sequence_number":4,"output_index":0,"item_id":"item_reasoning","delta":"The user wants a reply","summary_index":0}

event: response.reasoning_summary_text.delta
data: {"type":"response.reasoning_summary_text.delta","sequence_number":5,"output_index":0,"item_id":"item_reasoning","delta":" of exactly \"pong\".","summary_index":0}

event: response.reasoning_summary_text.done
data: {"type":"response.reasoning_summary_text.done","sequence_number":6,"output_index":0,"item_id":"item_reasoning","text":"The user wants a reply of exactly \"pong\".","summary_index":0}

event: response.reasoning_summary_part.done
data: {"type":"response.reasoning_summary_part.done","sequence_number":7,"output_index":0,"item_id":"item_reasoning","part":{"type":"summary_text","text":"The user wants a reply of exactly \"pong\"."},"summary_index":0}

event: response.output_item.done
data: {"type":"response.output_item.done","sequence_number":8,"output_index":0,"item":{"id":"item_reasoning","type":"reasoning","summary":[{"text":"The user wants a reply of exactly \"pong\".","type":"summary_text"}]}}

event: response.output_item.added
data: {"type":"response.output_item.added","sequence_number":9,"output_index":1,"item":{"id":"item_message","type":"message","role":"assistant","content":[],"status":"in_progress"}}

event: response.content_part.added
data: {"type":"response.content_part.added","sequence_number":10,"output_index":1,"item_id":"item_message","content_index":0,"part":{"type":"output_text","text":"","annotations":[]}}

event: response.output_text.delta
data: {"type":"response.output_text.delta","sequence_number":11,"output_index":1,"item_id":"item_message","content_index":0,"delta":"pong"}

event: response.output_text.done
data: {"type":"response.output_text.done","sequence_number":12,"output_index":1,"item_id":"item_message","content_index":0,"text":"pong"}

event: response.content_part.done
data: {"type":"response.content_part.done","sequence_number":13,"output_index":1,"item_id":"item_message","content_index":0,"part":{"type":"output_text","text":"pong","annotations":[]}}

event: response.output_item.done
data: {"type":"response.output_item.done","sequence_number":14,"output_index":1,"item":{"id":"item_message","type":"message","role":"assistant","content":[{"type":"output_text","annotations":[],"text":"pong"}],"status":"completed"}}

event: response.completed
data: {"type":"response.completed","sequence_number":15,"response":{"object":"response","id":"resp_example","created_at":1791015238,"model":"grok-4.7","output":[{"id":"item_reasoning","type":"reasoning","status":"in_progress","summary":[{"text":"The user wants a reply of exactly \"pong\".","type":"summary_text"}]},{"id":"item_message","type":"message","role":"assistant","content":[{"type":"output_text","text":"pong"}],"status":"completed"}],"status":"completed","usage":{"input_tokens":1248,"input_tokens_details":{"cached_tokens":1152},"output_tokens":55,"output_tokens_details":{"reasoning_tokens":54},"total_tokens":1303}},"output_index":0}
```

## Nén hội thoại

```txt
POST https://llmoxy.com/v1/responses/compact
```

Các trường là `model` (bắt buộc), `input`, `instructions`, `previous_response_id`. Lần đo grok ở trên không gọi route này.

Đây là bản markdown của https://vi.llmoxy.com/docs/api-reference/responses.
