API Docs

Tổng quan

Wrapper AI cung cấp HTTP API để gửi yêu cầu đến các mô hình AI (Gemini). Mọi request cần API Key hợp lệ từ trang Dashboard.

Endpoints

POST https://ai.webnew.info.vn/api/request // Gửi yêu cầu tới AI GET https://ai.webnew.info.vn/api/history // Lấy lịch sử xử lý

Content-Type

Content-Type: application/json

Xác thực

Truyền API Key qua header api-key. Bắt buộc với mọi request.

Header

api-key: your_api_key_here

Tham số Request Body – POST /api/request

Tham sốLoạiBắt buộcMô tả
text string Bắt buộc Nội dung câu hỏi / yêu cầu gửi đến AI.
tool_type string Tùy chọn Loại xử lý: text (văn bản, mặc định) hoặc image (tạo hình ảnh).
option string Tùy chọn Mức model: fast (nhanh, mặc định), think (suy luận), pro (mạnh nhất).

Loại xử lý (tool_type + option) & Thời gian xử lý

tool_typeoptionMô tảThời gianTrực quan
text fast Văn bản – xử lý nhanh ~ 30 giây
~30s
text think Văn bản – suy luận ~ 30 giây
~30s
text pro Văn bản – model mạnh nhất ~ 50 giây
~50s
image think Tạo hình ảnh – suy luận ~ 1 phút 30 giây
~90s
image fast Tạo hình ảnh – xử lý nhanh ~ 1 – 1 phút 10 giây
60–70s
image pro Tạo hình ảnh chuyên sâu ~ 2 phút
~2 phút
Thời gian xử lý phụ thuộc vào tải hệ thống. Đặt timeout phía client tối thiểu 150 giây khi dùng tool_type=image.

Ví dụ Code

cURL

curl -X POST "https://ai.webnew.info.vn/api/request" \ -H "api-key: your_api_key_here" \ -H "Content-Type: application/json" \ -d '{ "text": "Hello", "tool_type": "text", "option": "fast" }'

JavaScript (fetch)

const res = await fetch('https://ai.webnew.info.vn/api/request', { method : 'POST', headers: { 'Content-Type': 'application/json', 'api-key' : 'your_api_key_here', }, body: JSON.stringify({ text : 'Tóm tắt đoạn văn: ...', tool_type: 'text', option : 'pro', }), }); const data = await res.json(); console.log(data.result);

PHP (curl)

$ch = curl_init('https://ai.webnew.info.vn/api/request'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 150, CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'api-key: your_api_key_here', ], CURLOPT_POSTFIELDS => json_encode([ 'text' => 'Giải thích AI.', 'tool_type' => 'text', 'option' => 'think', ]), ]); $result = json_decode(curl_exec($ch), true);

Python

import requests resp = requests.post( 'https://ai.webnew.info.vn/api/request', headers={'api-key': 'your_api_key_here'}, json={'text': 'Hello!', 'tool_type': 'text', 'option': 'fast'}, timeout=150, ) print(resp.json()['result'])

Cấu trúc Response

HTTP status luôn là 200. Kiểm tra trường code trong JSON để biết thành công hay lỗi.

Thành công – code 200
{ "message" : "OK", "code" : 200, "noti" : "", "result" : "Nội dung trả về từ AI...", "image_urls": [], "request_id": "67a3f2b1c4d5e", "api_key_id": 42 }
Lỗi – code khác 200
{ "message" : "Error verifying API key", "code" : 401, "noti" : "", "result" : "", "image_urls": [], "request_id": "", "api_key_id": 0 }

Mã lỗi (trường code)

codemessageXử lý
200OKXử lý thành công.
400Data not found or invalid dataBody JSON không hợp lệ, thiếu trường text, hoặc tool_type/option không tồn tại.
401Error verifying API keyThiếu header api-key hoặc key không hợp lệ / chưa được cấp.
403ForbiddenAPI Key đã đạt giới hạn sử dụng. Kiểm tra quota trong Dashboard.
404Endpoint not foundURL không đúng. Kiểm tra lại địa chỉ endpoint.
405Method Not Allowed/api/request chỉ nhận POST, /api/history chỉ nhận GET.
408Don't server Ai readyKhông có server AI nào đang hoạt động khớp với yêu cầu.
409Api Name don't supportTrường api_name không được hỗ trợ.
500Internal Server ErrorLỗi hệ thống. Thử lại sau 30s, liên hệ hỗ trợ kèm request_id.

Ghi chú & Thực hành tốt

  • Đặt timeout tối thiểu 60s cho text và 150s cho request tạo hình.
  • HTTP status luôn 200. Dùng trường code trong JSON để xác định thành công/lỗi.
  • Kết quả tạo hình trả về trong image_urls (mảng URL). Trường result có thể chứa text mô tả kèm theo hình ảnh.
  • Dùng train để truyền prompt hệ thống / hướng dẫn bổ sung mà không cần gộp vào text.
  • API Key bị reset khi bấm "Tạo token mới" trong Dashboard – cập nhật lại ngay.
  • Kết quả trả về luôn là UTF-8, không cần decode thêm.
  • Hỗ trợ kỹ thuật: aboyit@hotmail.com – kèm request_id trong response lỗi.