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

# Junie CLI

> 通过自定义模型配置文件（Chat Completions 或 Anthropic Messages）将 JetBrains 的 Junie CLI 连接到 Hostlinku

[Junie CLI](https://junie.jetbrains.com/docs/custom-llm-models.html) - JetBrains 面向终端的代理编码工具 - 支持以 JSON 文件形式定义的 **自定义模型配置文件**。一个配置文件包含端点、API 格式、API 密钥，以及用于轻量级任务的主模型和快速模型（*faster model*）。

有关 JetBrains IDE 中的 AI 助手，请参阅 [JetBrains AI 助手](https://docs.hostlinku.com/zh/integrations/jetbrains.md)。

### 安装 Junie CLI 并保存 API 密钥

```bash theme={null}
curl -fsSL https://junie.jetbrains.com/install.sh | bash
export HOSTLINKU_API_KEY=sk-your-api-key
```

### 创建 Hostlinku 个人资料

Junie 在 `~/.junie/models/*.json`（用户级别）和 `.junie/models/*.json`（项目级别）中查找配置文件。不包含 `.json` 的文件名即为配置文件 ID。创建 `~/.junie/models/hostlinku.json`：

```json theme={null}
{
  "displayName": "Hostlinku",
  "id": "claude-sonnet-4-6",
  "baseUrl": "https://api.hostlinku.com/v1/chat/completions",
  "apiType": "OpenAICompletion",
  "apiKey": "${HOSTLINKU_API_KEY}",
  "maxContextLength": 1000000,
  "fasterModel": {
    "id": "claude-haiku-4-5",
    "maxContextLength": 200000
  }
}
```

baseUrl 是完整的端点 URL

Junie **没有**向`baseUrl`添加任何路径。对于`OpenAICompletion`，写到`/v1/chat/completions`；对于`Anthropic`，写到`/v1/messages`。

### 使用配置文件运行

```bash theme={null}
junie --model custom:hostlinku
```

该配置文件还会显示在 TUI 模型列表的 **自定义** 选项卡中，并可通过命令 `/model` 访问。首次请求会显示在控制台 → **请求日志** 中。

## 模型：Anthropic

对于采用 Messages API（全提示缓存）的 Claude 模型，请创建第二个配置文件，例如 `~/.junie/models/hostlinku-claude.json`：

```json theme={null}
{
  "displayName": "Hostlinku (Anthropic)",
  "id": "claude-sonnet-4-6",
  "baseUrl": "https://api.hostlinku.com/v1/messages",
  "apiType": "Anthropic",
  "apiKey": "${HOSTLINKU_API_KEY}",
  "fasterModel": { "id": "claude-haiku-4-5" }
}
```

然后运行 `junie --model custom:hostlinku-claude`。

## 需知事项

* **`${HOSTLINKU_API_KEY}`** 在加载配置文件时从环境变量中读取。如果该变量尚未设置，配置文件加载将失败，且 Junie 会提示缺失的变量名称-这对于提交到代码库的配置文件来说是安全的（`.junie/models/`）。
* **主力机型与更快的机型。** 为主模型选择具有强大*工具调用*功能的模型（`claude-sonnet-4-6`、`gpt-5-5`）；而对于快速模型（摘要与分类），`claude-haiku-4-5`或`deepseek-v4-flash`等低成本模型已足够。
* **Responses API (`OpenAIResponses`)** 在 `https://api.hostlinku.com/v1/responses` 中同样可用，但属于 *无状态* 类型 ([详情](https://docs.hostlinku.com/zh/responses.md))。`OpenAICompletion` 是最安全的选择。

## 故障排除

| 症状 | Solusi |
| - | - |
| `404` | `baseUrl` 尚未完成-应以 `/v1/chat/completions` 或 `/v1/messages` 结尾。 |
| 个人资料未显示 | 文件名/位置错误，或 JSON 格式无效。配置文件 = 不包含 `.json` 的文件名。 |
| 环境变量错误 | 在运行 `junie` 的 shell 中导出 `HOSTLINKU_API_KEY`。 |
| 呼叫工具失败 / 代理程序无限循环 | 该模型对于代理编码而言过于小-请将主模型替换为[概述](https://docs.hostlinku.com/zh/integrations.md)中的推荐模型。 |


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