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

# CometAPI CLI

> 安装并使用 CometAPI 命令行界面，在终端中与模型聊天、浏览模型元数据、运行多协议请求、检查余额以及查看用量。

[CometAPI CLI](https://pypi.org/project/cometapi-cli/) 是 CometAPI 的官方命令行工具。它可以帮助你在终端中与模型聊天、查看模型目录、发送一次性请求、检查余额以及浏览账户用量。

请使用 [PyPI 包页面](https://pypi.org/project/cometapi-cli/) 作为安装和包元数据的公开主页。本文档在无需访问私有源代码仓库的情况下，对相同命令进行了进一步说明。

<Note>
  CometAPI CLI 目前处于 beta 阶段。在界面稳定之前，命令名称和选项可能会发生变化。
</Note>

## 功能

* 使用流式输出（Streaming）或交互式 REPL 与模型聊天
* 浏览模型目录元数据，包括 provider、modality、endpoint、capability、context 和 pricing 字段
* 使用 `cometapi model info <id>` 查看单个模型
* 使用 `cometapi run` 通过 聊天补全、响应、Anthropic 消息 或 Gemini 生成内容 格式发送一次请求
* 检查余额、账户资料、用量统计、API keys、日志和异步任务历史
* 输出 table、JSON、YAML、CSV 或 Markdown 数据
* 将本地配置存储在 `~/.config/cometapi/config.toml`

## 前置条件

* Python 3.10 或更高版本
* 一个 [CometAPI API key](https://www.cometapi.com/console/token)

## 安装 CLI

从 PyPI 安装该包：

<CodeGroup>
  ```bash pip theme={null}
  pip install cometapi-cli
  ```

  ```bash pipx theme={null}
  pipx install cometapi-cli
  ```

  ```bash uv theme={null}
  uv tool install cometapi-cli
  ```
</CodeGroup>

验证已安装的命令：

```bash theme={null}
cometapi --version
cometapi -h
```

## 开始使用 CLI

<Steps>
  <Step title="配置凭据">
    运行设置向导：

    ```bash theme={null}
    cometapi init
    ```

    你也可以使用环境变量配置 API key：

    ```bash theme={null}
    export COMETAPI_KEY="your-api-key"
    ```

    可选的 `COMETAPI_ACCESS_TOKEN` 值仅在 account、stats、tokens、logs 和 tasks 命令中需要。
  </Step>

  <Step title="与模型聊天">
    发送一条聊天消息：

    ```bash theme={null}
    cometapi chat "Explain CometAPI in one sentence."
    ```

    不带消息运行 `cometapi chat` 以启动聊天 REPL。
  </Step>

  <Step title="浏览模型">
    搜索公开模型目录：

    ```bash theme={null}
    cometapi models --search gpt --limit 10
    ```

    按目录元数据筛选：

    ```bash theme={null}
    cometapi models --provider openai --type chat --limit 10
    cometapi models --feature image --endpoint responses --json
    ```
  </Step>

  <Step title="查看单个模型">
    显示单个模型的详细元数据：

    ```bash theme={null}
    cometapi model info your-model-id
    ```

    输出原始详细负载：

    ```bash theme={null}
    cometapi model info your-model-id --json
    ```
  </Step>

  <Step title="运行多协议请求">
    通过默认聊天 endpoint 发送一次性请求：

    ```bash theme={null}
    cometapi run your-model-id -p "Reply with OK only."
    ```

    当你的请求体遵循不同的 provider schema 时，选择另一种 endpoint 格式：

    ```bash theme={null}
    cometapi run your-model-id --endpoint responses -p "Reply with OK only." --json
    cometapi run your-model-id --endpoint anthropic -p "Reply with OK only." -i max_tokens=32
    cometapi run your-model-id --endpoint gemini -p "Reply with OK only." -i generationConfig.maxOutputTokens=32
    ```
  </Step>
</Steps>

## 获取命令帮助

在根命令或任何子命令上使用 `-h`，查看已安装版本的选项：

```bash theme={null}
cometapi -h
cometapi models -h
cometapi model info -h
cometapi run -h
```

## 主要命令

| 命令                | 描述                                            |
| ----------------- | --------------------------------------------- |
| `chat [MESSAGE]`  | 发送聊天消息或启动聊天 REPL                              |
| `models`          | 列出并筛选模型目录元数据                                  |
| `model info <id>` | 查看单个模型的公开元数据                                  |
| `run [MODEL]`     | 通过 chat、responses、anthropic 或 gemini 格式发送一次请求 |
| `balance`         | 显示账户或 API key 余额                              |
| `account`         | 显示账户资料                                        |
| `stats`           | 显示使用统计                                        |
| `tokens`          | 列出并搜索 API key                                 |
| `logs`            | 浏览使用日志并导出 CSV                                 |
| `tasks`           | 浏览异步任务日志                                      |
| `init`            | 运行设置向导                                        |
| `doctor`          | 运行配置诊断                                        |
| `config`          | 管理本地配置                                        |
| `repl`            | 启动交互式命令 shell                                 |

## 链接

* [PyPI package](https://pypi.org/project/cometapi-cli/)
* [命令参考](/zh-Hans/libraries/cli/commands)
* [配置指南](/zh-Hans/libraries/cli/configuration)
