# Ký request TikTok web

`POST https://api.tiksign.com/api/v1/sign/web`

- Giá: từ 90đ / lần gọi
  - 0 – 10.000 req: 150đ / lần gọi
  - 10.001 – 100.000 req: 120đ / lần gọi
  - Trên 100.000 req: 90đ / lần gọi
- Đang hoạt động
- Cập nhật lần cuối: 2026-10-17

Gửi URL TikTok web đầy đủ (`www.tiktok.com`). Nhận về `signed_url` đã gắn `X-Dynosaur`, `X-Gnarly`, `msToken` và `X-Bogus=1`.

**Cách dùng**

1. Gọi endpoint này với `url` — URL đầy đủ với toàn bộ tham số như trang của bạn gửi — và `cookie` (phiên của bạn, để chữ ký dùng đúng `msToken`).
2. Gọi TikTok bằng đúng `signed_url`, kèm cookie phiên của bạn, `user_agent` và `referer` trả về.
3. Ký mới cho mỗi request: chữ ký phụ thuộc URL và thời điểm.

Không cần device. Request POST thì gửi thêm `body` để chữ ký phủ đúng.

Mỗi lần gọi thành công trừ tiền ví theo bảng giá lũy tiến (gói PAYG). Gói 30 ngày không trừ theo request.

## Xác thực

- `X-API-Key: YOUR_API_KEY`
- `Authorization: Bearer YOUR_API_KEY`

## Request body

`application/json`

| Tên | Kiểu | Bắt buộc | Mô tả |
| --- | --- | --- | --- |
| `url` | `string<uri>` | Bắt buộc | URL https đầy đủ của request TikTok web, kèm toàn bộ tham số như trang gửi. |
| `cookie` | `string` | Tuỳ chọn | Cookie phiên TikTok web của bạn — service lấy `msToken` từ cookie để ký đúng phiên bạn sẽ gửi. Bỏ trống thì service tự sinh msToken. |
| `body` | `string` | Tuỳ chọn | Body của request POST (nếu có) — chữ ký phủ body nên phải khớp khi gửi. |
| `referer` | `string<uri>` | Tuỳ chọn | Trang ngữ cảnh (referer). Mặc định `https://www.tiktok.com/`. |
| `profile` | `string` (enum: desktop \| mobile, default: "desktop") | Tuỳ chọn | Hồ sơ thiết bị — chọn sẵn `user_agent` mặc định. |
| `ua` | `string` | Tuỳ chọn | User-Agent tuỳ chỉnh (phải khớp UA lúc gửi request thật). |
| `msToken` | `string` | Tuỳ chọn | msToken của phiên bạn. Bỏ trống thì service sinh mới — một số endpoint cần msToken do phiên phát. |

```json
{
  "url": "https://www.tiktok.com/api/comment/list/?aweme_id=7663366594881457430&count=20&cursor=0",
  "referer": "https://www.tiktok.com/@tiksign/video/7663366594881457430",
  "profile": "desktop"
}
```

## Phản hồi

### 200

Ký thành công.

| Tên | Kiểu | Bắt buộc | Mô tả |
| --- | --- | --- | --- |
| `trace_id` | `string` | Bắt buộc | Mã tra cứu, tìm lại trong mục Logs. |
| `host` | `string` | Bắt buộc | Host của URL đã ký. |
| `signed_url` | `string` | Bắt buộc | Gọi TikTok bằng đúng URL này (đã gắn `X-Dynosaur`, `msToken`, `X-Bogus=1`, `X-Gnarly`). |
| `profile` | `string` (enum: desktop \| mobile) | Bắt buộc | Hồ sơ thiết bị đã dùng để ký. |
| `user_agent` | `string` | Bắt buộc | Gửi request với đúng User-Agent này (chữ ký gắn với UA). |
| `referer` | `string<uri>` | Bắt buộc | Gửi request với referer này (mặc định trang chủ nếu bạn không truyền). |
| `latency_ms` | `integer` | Bắt buộc | Thời gian ký, tính bằng mili giây. |

```json
{
  "trace_id": "tr_2f7c9d1e5a6b4c3d",
  "host": "www.tiktok.com",
  "signed_url": "https://www.tiktok.com/api/comment/list/?aweme_id=7663366594881457430&count=20&cursor=0&X-Dynosaur=MCxbbHqtL3e9acYBNEExdco17Bp…&msToken=7c0b…==&X-Bogus=1&X-Gnarly=gpaK7uw…",
  "profile": "desktop",
  "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/154.0.0.0 Safari/537.36",
  "referer": "https://www.tiktok.com/@tiksign",
  "latency_ms": 3
}
```

## Lỗi

- **400**: URL không phải https đầy đủ, không thuộc `*.tiktok.com`, thiếu query string, hoặc `profile` sai. Cách xử lý: gửi `url` https đầy đủ kèm tham số như trang thật gửi.
- **401**: Thiếu API key, key sai hoặc đã thu hồi. Cách xử lý: kiểm tra header `X-API-Key`.
- **402**: Gói PAYG: số dư ví không đủ trả cho request. Cách xử lý: nạp tiền ở mục Ví & gói cước, hoặc mua gói 30 ngày.
- **429**: Vượt số request mỗi giây của gói. Cách xử lý: đợi theo header `Retry-After` rồi gửi lại, hoặc nâng gói để có RPS cao hơn.
- **502**: Worker ký nội bộ lỗi. Cách xử lý: thử lại sau vài giây; nếu lặp lại, gửi `trace_id` cho hỗ trợ. Lần gọi lỗi không bị trừ tiền.

## Ví dụ request

```bash
curl -X POST 'https://api.tiksign.com/api/v1/sign/web' \
  -H 'X-API-Key: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
  "url": "https://www.tiktok.com/api/comment/list/?aweme_id=7663366594881457430&count=20&cursor=0",
  "referer": "https://www.tiktok.com/@tiksign/video/7663366594881457430",
  "profile": "desktop"
}'
```

```javascript
const response = await fetch("https://api.tiksign.com/api/v1/sign/web", {
  method: "POST",
  headers: {
    "X-API-Key": "YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "url": "https://www.tiktok.com/api/comment/list/?aweme_id=7663366594881457430&count=20&cursor=0",
    "referer": "https://www.tiktok.com/@tiksign/video/7663366594881457430",
    "profile": "desktop"
  }),
});
const data = await response.json();
console.log(response.status, data);
```

```python
import requests

response = requests.post(
    "https://api.tiksign.com/api/v1/sign/web",
    headers={
        "X-API-Key": "YOUR_API_KEY",
        "Content-Type": "application/json",
    },
    json={
        "url": "https://www.tiktok.com/api/comment/list/?aweme_id=7663366594881457430&count=20&cursor=0",
        "referer": "https://www.tiktok.com/@tiksign/video/7663366594881457430",
        "profile": "desktop",
    },
    timeout=10,
)
print(response.status_code, response.json())
```

```go
package main

import (
	"bytes"
	"fmt"
	"io"
	"net/http"
)

func main() {
	body := []byte(`{
  "url": "https://www.tiktok.com/api/comment/list/?aweme_id=7663366594881457430&count=20&cursor=0",
  "referer": "https://www.tiktok.com/@tiksign/video/7663366594881457430",
  "profile": "desktop"
}`)
	req, err := http.NewRequest("POST", "https://api.tiksign.com/api/v1/sign/web", bytes.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("X-API-Key", "YOUR_API_KEY")
	req.Header.Set("Content-Type", "application/json")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	data, err := io.ReadAll(res.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(res.StatusCode, string(data))
}
```
