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

# CLI

> 从终端发现、运行、等待和导出 SocQ 任务。

# CLI

使用 SocQ CLI 在终端中运行或自动执行数据采集任务，并将标准化结果导出为 JSON、JSONL、CSV 或表格。

## 安装并验证

```bash theme={"system"}
npm install -g @socq/cli
socq auth login
```

对于 CI，设置 `SOCQ_API_KEY` 而不是使用交互式登录。在正常终端使用中避免使用 `--api-key`，因为命令参数可能保留在 shell 历史记录或进程列表中。

## 查找 API

```bash theme={"system"}
socq platforms
socq tools youtube
socq describe youtube/comments
```

编写自动化脚本前，请先运行 `describe`，查看能力目录中最新的输入参数和计费信息。

## 完成首次采集

```bash theme={"system"}
socq youtube comments \
  --urls "https://www.youtube.com/watch?v=VIDEO_ID" \
  --sort-by newest \
  --wait
```

动态命令直接映射到：

```text theme={"system"}
REST:      POST /v1/youtube/comments
Endpoint:  youtube/comments
MCP tool:  socq_youtube_comments
CLI:       socq youtube comments
```

当输入来自文件时，使用稳定的通用形式：

```bash theme={"system"}
socq run youtube comments \
  --input-file request.json \
  --format jsonl \
  --output results.jsonl \
  --wait
```

## 恢复而不重新提交

如果命令在采集完成之前返回，请保留任务 ID：

```bash theme={"system"}
socq task get TASK_ID
socq task wait TASK_ID --timeout 180
socq task results TASK_ID --result-fields id,url,text,author.username --format csv --output results.csv
socq task files TASK_ID
```

任务结果统一使用固定资源 Schema，可通过 `--result-fields` 获取更小的字段投影。

不要因为本地等待超时就重新提交采集请求，请继续查询现有任务。

## 标记 Agent Skill 执行来源

普通 CLI 提交会记录为 `request_source="cli"`。当 Agent Skill 改用 CLI 执行时，请在提交命令中加入来源标记：

```bash theme={"system"}
socq youtube comments --urls "https://www.youtube.com/watch?v=VIDEO_ID" --request-source skill
```

设置 `SOCQ_REQUEST_SOURCE=skill` 也有相同效果。新任务会记录为 `skill-cli`；轮询任务时不需要添加此标记。

## 输出格式

| 格式 | 适用场景 |
| - | - |
| `table` | 在终端中查看少量结果 |
| `json` | 结构化输出和脚本 |
| `jsonl` | 流式处理或大量导出 |
| `csv` | 电子表格和数据分析 |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.