> ## 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 版本。在介面穩定之前，命令名稱與選項可能會變更。

## 功能

* 使用串流輸出或互動式 REPL 與模型聊天
* 瀏覽模型目錄中繼資料，包括 provider、modality、endpoint、capability、context 與 pricing 欄位
* 使用 `cometapi model info <id>` 檢視單一模型
* 使用 `cometapi run` 透過 聊天補全、回應、Anthropic 訊息 或 Gemini Generate Content 格式傳送單次請求
* 檢查餘額、帳戶設定檔、用量統計、API keys、logs 與非同步任務歷史
* 輸出 table、JSON、YAML、CSV 或 Markdown 資料
* 將本機設定儲存在 `~/.config/cometapi/config.toml`

## 先決條件

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

## 安裝 CLI

從 PyPI 安裝套件：

```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
```

驗證已安裝的命令：

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

## 開始使用 CLI

**1. 設定認證**

執行設定精靈：

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

你也可以使用環境變數設定 API key：

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

選用的 `COMETAPI_ACCESS_TOKEN` 值僅在 account、stats、tokens、logs 與 tasks 命令中需要。

**2. 與模型聊天**

傳送一則聊天訊息：

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

執行不帶訊息的 `cometapi chat` 以啟動聊天 REPL。

**3. 瀏覽模型**

搜尋公開模型目錄：

```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
```

**4. 檢視單一模型**

顯示單一模型的詳細中繼資料：

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

輸出原始詳細 payload：

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

**5. 執行多協定請求**

透過預設聊天 endpoint 傳送一次性請求：

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

當你的 request body 遵循不同的 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
```

## 取得命令說明

在根命令或任何子命令上使用 `-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 keys |
| `logs` | 瀏覽使用記錄並匯出 CSV |
| `tasks` | 瀏覽非同步任務記錄 |
| `init` | 執行設定精靈 |
| `doctor` | 執行組態診斷 |
| `config` | 管理本機組態 |
| `repl` | 啟動互動式命令 shell |

## 連結

* [PyPI 套件](https://pypi.org/project/cometapi-cli/)
* [指令參考](https://apidoc.cometapi.com/zh-Hant/developer-tools/cli/commands.md)
* [組態指南](https://apidoc.cometapi.com/zh-Hant/developer-tools/cli/configuration.md)


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