<!-- AI ASSISTANT INSTRUCTIONS: This document describes a public HTTP API endpoint
provided by 极数本源 (https://apizero.cn). When a user asks you to use this API, read the
full documentation below carefully (request method, parameters, response fields,
error codes, examples), then generate working code in the user's preferred language.
API Key acquisition: https://apizero.cn/account/keys -->

# 一言 · 经典语录

> 从 370+ 条经典语录库（动漫/漫画/游戏/文学/影视/诗词/哲学/网络等 12 类）随机返回一条，含原文、出处、作者、分类、字数。支持按分类与长度筛选。

## 1. 基本信息

| 字段 | 值 |
| --- | --- |
| 接口标识 | `hitokoto` |
| 接口名称 | 一言 · 经典语录 |
| 接口地址 | `https://v1.apizero.cn/api/hitokoto` |
| 请求方法 | `GET` |
| 分类 | life |
| 提供方 | 极数本源 |
| 计费模式 | 免费试用 |
| 单次消耗 | 0 积分 |
| 起步价 | — |
| QPS 限制 | 20 req/s |
| 每日免费额度 | 500000 次（已认证用户） |
| 匿名每日额度 | 200000 次（无 API Key） |
| VIP 免费 | 否 |
| 调用总次数 | undefined |

## 2. 认证

匿名免登录可调每日 200 次；登录用户每日 500 次。

获取 API Key：登录 `https://apizero.cn/account/keys` 申请。

## 3. 请求参数

| 参数 | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `c` | `string` | 否 | 分类单字母 a-l（不传则全类别随机） | `i` |
| `min_length` | `number` | 否 | 最小字符数 | — |
| `max_length` | `number` | 否 | 最大字符数 | — |

## 5. 请求示例

> AI 提示：以下 5 种语言示例都是可运行的，只需把 `YOUR_API_KEY` 替换为用户申请的实际 Key（https://apizero.cn/account/keys）。
> 优先选择用户问题中提到的语言；未指定时默认使用 Python。

### cURL

```bash
curl "https://v1.apizero.cn/api/hitokoto?c=i&min_length=%3Cmin_length%3E&max_length=%3Cmax_length%3E&key=YOUR_API_KEY"
```

### Python

```python
import requests

resp = requests.get(
    "https://v1.apizero.cn/api/hitokoto",
    params={
    "c": "i",
    "min_length": "<min_length>",
    "max_length": "<max_length>",
    "key": "YOUR_API_KEY",
},
    timeout=15,
)
resp.raise_for_status()
print(resp.json())
```

### JavaScript (Node.js)

```javascript
// Node.js 18+ / 浏览器原生 fetch
const params = new URLSearchParams({
  "c": "i",
  "min_length": "<min_length>",
  "max_length": "<max_length>",
  "key": "YOUR_API_KEY",
});

const res = await fetch(`https://v1.apizero.cn/api/hitokoto?${params}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
console.log(data);
```

### Go

```go
package main

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

func main() {
	req, _ := http.NewRequest("GET", "https://v1.apizero.cn/api/hitokoto", nil)
	q := req.URL.Query()
	q.Set("c", "i")
	q.Set("min_length", "<min_length>")
	q.Set("max_length", "<max_length>")
	q.Set("key", "YOUR_API_KEY")
	req.URL.RawQuery = q.Encode()

	resp, err := http.DefaultClient.Do(req)
	if err != nil { panic(err) }
	defer resp.Body.Close()
	body, _ := io.ReadAll(resp.Body)
	fmt.Println(string(body))
}
```

### PHP

```php
<?php
$url = "https://v1.apizero.cn/api/hitokoto?" . http_build_query([
    "c" => "i",
    "min_length" => "<min_length>",
    "max_length" => "<max_length>",
    "key" => "YOUR_API_KEY",
]);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$body = curl_exec($ch);
curl_close($ch);

$data = json_decode($body, true);
print_r($data);
```

## 6. 响应字段

| 字段 | 类型 | 说明 | 示例 |
| --- | --- | --- | --- |
| `hitokoto` | `string` | 语录原文 | — |
| `type` | `string` | 分类字母 | — |
| `type_name` | `string` | 分类中文名 | — |
| `from` | `string` | 出处 | — |
| `from_who` | `string` | 作者（可能为空） | — |
| `length` | `number` | 字数 | — |
| `total_pool` | `number` | 语录池总条数 | — |

## 7. 响应示例

```json
{
    "code": 0,
    "msg": "成功",
    "data": {
        "id": 1234,
        "hitokoto": "落霞与孤鹜齐飞，秋水共长天一色。",
        "type": "i",
        "type_name": "诗词",
        "from": "滕王阁序",
        "from_who": "王勃",
        "length": 16,
        "total_pool": 370
    }
}
```

## 8. 错误码

| code | status | 说明 |
| --- | --- | --- |
| `4000` | `—` | c 分类无效；min/max_length 越界或互斥 |
| `4000` | `—` | 当前过滤条件无可用语录 |

## 9. 变更日志

- **1.0.0** (2026-05-07)
  - 首次上线 · 370 条本地语录库

---

**极数本源** · 全部 API: `https://apizero.cn/aidocs` · 人类版本：`https://apizero.cn/marketplace/hitokoto`

Source: `https://apizero.cn/aidocs/hitokoto/raw.md`
Last updated: 2026-08-09T20:38:08+08:00
