> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/clore.ai/clore.ai-eng-zh/kai-fa-zhe/cli-guide.md).

# CLI 参考

该 `clore` CLI 允许你直接从终端管理 Clore.ai GPU 市场——搜索 GPU、部署实例、通过 SSH 登录，并且无需编写任何代码即可管理订单。

***

## 安装

```bash
pip install clore-ai
```

这会安装 Python SDK 和 `clore` CLI 命令。

**要求：** Python 3.9+

***

## 配置

### 设置你的 API 密钥

从以下位置获取你的密钥： [Clore.ai 仪表板](https://clore.ai) → **API** 部分，然后进行配置：

```bash
clore config set api_key YOUR_API_KEY
```

这会将密钥保存到 `~/.clore/config.json`.

### 或者使用环境变量

```bash
export CLORE_API_KEY=your_api_key_here
```

### 查看当前配置

```bash
# 显示所有配置
clore config show

# 获取特定值
clore config get api_key
```

***

## 命令

| 命令                                    | 描述               |
| ------------------------------------- | ---------------- |
| `clore search`                        | 搜索 GPU 市场        |
| `clore deploy <server_id>`            | 创建新订单（租用服务器）     |
| `clore orders`                        | 列出你的订单           |
| `clore cancel <order_id>`             | 取消订单             |
| `clore ssh <order_id>`                | 通过 SSH 登录到一个活跃订单 |
| `clore wallets`                       | 显示钱包余额           |
| `clore servers`                       | 列出你托管的服务器        |
| `clore server-config <name>`          | 获取服务器配置          |
| `clore spot <server_id>`              | 查看某个服务器的现货市场     |
| `clore spot-price <order_id> <price>` | 设置现货价格           |
| `clore config set <key> <value>`      | 设置配置值            |
| `clore config get <key>`              | 获取配置值            |
| `clore config show`                   | 显示所有配置           |
| `clore --version`                     | 显示版本             |

***

## 详细用法

### `clore search`

使用筛选和排序搜索 GPU 市场。

```bash
# 列出所有可用服务器（按价格排序，前 20 个）
clore search

# 按 GPU 型号筛选
clore search --gpu "RTX 4090"

# 按 GPU 和最高价格筛选
clore search --gpu "RTX 4090" --max-price 5.0

# 多 GPU 设备
clore search --min-gpu 4

# 按 GPU 数量排序，显示前 10 个
clore search --sort gpu --limit 10

# 组合筛选条件
clore search --gpu "A100" --min-ram 128 --max-price 10.0 --sort price --limit 5
```

**选项：**

| 选项            | 类型  | 描述                           |
| ------------- | --- | ---------------------------- |
| `--gpu`       | 文本  | 按 GPU 型号筛选（例如 `"RTX 4090"`)  |
| `--min-gpu`   | 整数  | 最少 GPU 数量                    |
| `--min-ram`   | 浮点数 | 最小 RAM 容量，单位 GB              |
| `--max-price` | 浮点数 | 每小时 USD 最高价格                 |
| `--sort`      | 选项  | 排序依据： `价格` （默认）， `GPU`, `内存` |
| `--limit`     | 整数  | 最多显示结果数（默认：20）               |

**示例输出：**

```
🔍 GPU 市场
┏━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ ID  ┃ GPU                             ┃ Count ┃ RAM (GB) ┃ CPU                          ┃ Price/h (USD) ┃ Location ┃
┡━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ 123 │ 1x NVIDIA GeForce RTX 4090      │     1 │    64.0  │ AMD Ryzen 9 5900X            │       $0.3200 │ US       │
│ 456 │ 2x NVIDIA GeForce RTX 4090      │     2 │   128.0  │ Intel Core i9-13900K         │       $0.5800 │ DE       │
└─────┴─────────────────────────────────┴───────┴──────────┴──────────────────────────────┴───────────────┴──────────┘
显示 2 台服务器
```

***

### `clore deploy <server_id>`

创建一个新订单来租用 GPU 服务器。

```bash
# 按需订单并启用 SSH
clore deploy 123 \\
  --image cloreai/ubuntu22.04-cuda12 \\
  --type on-demand \\
  --currency bitcoin \\
  --ssh-password MySecurePass123 \\
  --port 22:tcp \\
  --port 8888:http

# 现货订单
clore deploy 123 \\
  --image cloreai/pytorch \\
  --type spot \\
  --currency bitcoin \\
  --spot-price 0.000005 \\
  --port 22:tcp

# 使用环境变量
clore deploy 123 \\
  --image cloreai/ubuntu22.04-cuda12 \\
  --type on-demand \\
  --currency bitcoin \\
  --ssh-password MyPass123 \\
  --port 22:tcp \\
  --env WANDB_API_KEY=your_key \\
  --env HF_TOKEN=your_token
```

**参数：**

| 参数          | 描述                           |
| ----------- | ---------------------------- |
| `server_id` | 要租用的服务器 ID（从 `clore search`) |

**选项：**

| 选项               | 类型  | 必需 | 描述                                                                       |
| ---------------- | --- | -- | ------------------------------------------------------------------------ |
| `--image`        | 文本  | 是  | Docker 镜像（例如 `cloreai/ubuntu22.04-cuda12`)                               |
| `--type`         | 选项  | 是  | `on-demand` 或 `spot`                                                     |
| `--currency`     | 文本  | 是  | 支付货币（例如 `bitcoin`)                                                       |
| `--ssh-password` | 文本  | 否  | SSH 密码（字母数字，最多 32 个字符）                                                   |
| `--ssh-key`      | 文本  | 否  | SSH 公钥                                                                   |
| `--port`         | 文本  | 否  | 端口映射（可重复），格式： `PORT:PROTOCOL`                                            |
| `--env`          | 文本  | 否  | 环境变量（可重复），格式： `KEY=VALUE`                                                |
| `--spot-price`   | 浮点数 | 否  | 每日报价（现货订单必需）                                                             |
| `--gpu-count`    | 整数  | 否  | 仅租用 N 个 GPU（部分租用，仅限按需）                                                   |
| `--gpu-indices`  | 文本  | 否  | 来自以下位置的逗号分隔 GPU 插槽： `partial_gpu_rental.free_indices` （需要 `--gpu-count`) |

***

### `clore orders`

列出你的活跃订单。

```bash
# 活跃订单
clore orders

# 包括已完成/已过期订单
clore orders --completed
```

**选项：**

| 选项            | 描述          |
| ------------- | ----------- |
| `--completed` | 包括已完成/已过期订单 |

**示例输出：**

```
📦 我的订单
┏━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ID ┃ Server ID ┃ Type      ┃ Status ┃ Image                             ┃ IP                      ┃
┡━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ 38 │ 6         │ on-demand │ Active │ cloreai/ubuntu22.04-cuda12        │ n1.c1.clorecloud.net    │
└────┴───────────┴───────────┴────────┴───────────────────────────────────┴─────────────────────────┘
总计：1 个订单
```

***

### `clore cancel <order_id>`

取消一个活跃订单。

```bash
# 取消订单
clore cancel 38

# 带问题报告取消
clore cancel 38 --issue "GPU was overheating"
```

**参数：**

| 参数         | 描述        |
| ---------- | --------- |
| `order_id` | 要取消的订单 ID |

**选项：**

| 选项        | 描述          |
| --------- | ----------- |
| `--issue` | 取消原因 / 问题报告 |

***

### `clore ssh <order_id>`

通过 SSH 自动连接到正在运行的订单。CLI 会从你的订单详情中解析主机名和端口。

```bash
# 以 root 用户连接（默认）
clore ssh 38

# 以其他用户连接
clore ssh 38 --user ubuntu
```

**参数：**

| 参数         | 描述        |
| ---------- | --------- |
| `order_id` | 要连接的订单 ID |

**选项：**

| 选项       | 默认     | 描述      |
| -------- | ------ | ------- |
| `--user` | `root` | SSH 用户名 |

***

### `clore wallets`

显示你的钱包余额和充值地址。

```bash
clore wallets
```

**示例输出：**

```
💰 钱包余额
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Currency         ┃ Balance      ┃ Deposit Address                           ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ bitcoin          │ 0.00153176   │ tb1q6erw7v02t7hakgmlcl4wfnlykzqj05alndruwr │
│ CLORE-Blockchain │ 150.00000000 │ cLr1q8x...                                │
└──────────────────┴──────────────┴───────────────────────────────────────────┘
```

***

### `clore servers`

列出你在市场上托管的服务器。

```bash
clore servers
```

***

### `clore server-config <name>`

获取你托管的某台特定服务器的配置。

```bash
clore server-config "MyGPU"
```

**示例输出：**

```
服务器：MyGPU
ID：42
已连接：True
在线：True
可见性：公开
最长租赁时长：72
GPU：NVIDIA GeForce RTX 4090
按需价格（USD）：$0.35
现货价格（USD）：$0.18
CPU：AMD Ryzen 9 5900X 12-Core Processor
RAM：64.0 GB
GPU：1x NVIDIA GeForce RTX 4090
```

***

### `clore spot <server_id>`

查看某台服务器当前的现货市场报价。

```bash
clore spot 6
```

**示例输出：**

```
📊 现货市场 - 服务器 6
┏━━━━━━━━━━┳━━━━━━━━━━━┓
┃ 订单 ID ┃ 价格     ┃
┡━━━━━━━━━━╇━━━━━━━━━━━┩
│ 39       │ 4.2e-06   │
└──────────┴───────────┘
```

***

### `clore spot-price <order_id> <price>`

更新你的现货市场报价价格。

```bash
clore spot-price 39 0.000003
```

> **注意：** 你只能每 600 秒下调一次现货价格，而且幅度有限。

***

### `clore config`

管理 CLI 配置。

```bash
# 设置 API 密钥
clore config set api_key YOUR_API_KEY

# 获取某个值
clore config get api_key

# 显示所有配置
clore config show
```

配置存储在 `~/.clore/config.json`.

***

## 工作流

### 搜索 → 租用 → SSH → 取消

一个典型的端到端工作流：

```bash
# 1. 找到一个低于每小时 $5 的 RTX 4090
clore search --gpu "RTX 4090" --max-price 5.0 --sort price --limit 5

# 2. 在最便宜的服务器上部署（例如 ID 123）
clore deploy 123 \\
  --image cloreai/ubuntu22.04-cuda12 \\
  --type on-demand \\
  --currency bitcoin \\
  --ssh-password MyPass123 \\
  --port 22:tcp \\
  --port 8888:http

# 3. 检查你的订单状态
clore orders

# 4. 通过 SSH 登录到实例（例如订单 ID 456）
clore ssh 456

# 5. 完成后，取消订单
clore cancel 456
```

### 租用前监控余额

```bash
# 检查你是否有足够资金
clore wallets

# 搜索并租用
clore search --gpu "A100" --sort price --limit 3
clore deploy 789 \\
  --image cloreai/ubuntu22.04-cuda12 \\
  --type on-demand \\
  --currency bitcoin \\
  --ssh-password SecurePass \\
  --port 22:tcp
```

### 现货市场工作流

```bash
# 1. 查看某个服务器的现货报价
clore spot 6

# 2. 创建现货订单
clore deploy 6 \\
  --image cloreai/pytorch \\
  --type spot \\
  --currency bitcoin \\
  --spot-price 0.000005 \\
  --ssh-password MyPass123 \\
  --port 22:tcp

# 3. 调整你的现货价格
clore spot-price 39 0.000003
```

### 服务器托管管理

```bash
# 查看你的服务器
clore servers

# 检查服务器配置
clore server-config "MyGPU"
```

***

## 下一步

* [**Python SDK**](/clore.ai/clore.ai-eng-zh/kai-fa-zhe/python-sdk.md) — 使用 Python 自动化工作流
* [**REST API**](/clore.ai/clore.ai-eng-zh/mian-xiang-zhu-ji-ti-gong-zhe/api.md) — 原始 API 文档
* [**按需与现货**](/clore.ai/clore.ai-eng-zh/mian-xiang-zu-yong-zhe/on-demand-vs-spot.md) — 了解定价模型


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/clore.ai/clore.ai-eng-zh/kai-fa-zhe/cli-guide.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
