> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.tramlabs.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.tramlabs.io/_mcp/server.

# Junie CLI

> Sử dụng Trạm AI với JetBrains Junie CLI

## Sử dụng Junie CLI với Trạm AI

[Junie CLI](https://junie.jetbrains.com/) là công cụ agentic coding của JetBrains, cung cấp giao diện terminal tương tác để developer xem lại, viết và chỉnh sửa code. Khi kết nối Junie với Trạm AI, người dùng truy cập được hàng trăm model AI chỉ với một API key duy nhất, thay vì phải quản lý key riêng cho từng provider.

### Vì sao nên dùng Trạm AI với Junie?

* **Truy cập hàng trăm model** -- Sử dụng model từ Anthropic, OpenAI, Google, xAI, Meta và nhiều provider khác thông qua một API key duy nhất
* **Provider failover** -- Khi một provider không khả dụng hoặc đã chạm rate limit, Trạm AI sẽ tự động route sang provider khác
* **Quản lý chi phí tập trung** -- Theo dõi và quản lý chi tiêu cho tất cả model ngay trên [dashboard Trạm AI](https://console.tramlabs.io/settings/logs)
* **Kiểm soát theo nhóm** -- Đặt budget và giám sát mức sử dụng trên toàn tổ chức

### Yêu cầu trước

* Đã cài đặt [Junie CLI](https://junie.jetbrains.com/) (xem [Bước 1](#step-1-install-junie-cli) bên dưới)
* Một [API key Trạm AI](https://console.tramlabs.io/keys)

### Bước 1: Cài đặt Junie CLI

#### Linux / macOS

**`lines`**

```bash lines
curl -fsSL https://junie.jetbrains.com/install.sh | bash
```

#### Windows

**`lines`**

```powershell lines
powershell -NoProfile -ExecutionPolicy Bypass -Command "iex (irm 'https://junie.jetbrains.com/install.ps1')"
```

#### Homebrew

**`lines`**

```bash lines
brew tap jetbrains-junie/junie
brew update
brew install junie
```

Xác minh quá trình cài đặt:

**`lines`**

```bash lines
junie --version
```

### Bước 2: Cấu hình Trạm AI

Junie hỗ trợ sẵn Trạm AI như một provider BYOK (Bring Your Own Key). Người dùng chỉ cần đặt biến môi trường `JUNIE_TRAM_AI_API_KEY` để kết nối Junie với Trạm AI:

#### Shell Profile (Khuyến nghị)

Thêm biến môi trường vào shell profile để cấu hình được lưu lại cố định:

**`lines`**

```bash lines
# Open your shell profile
nano ~/.zshrc  # or ~/.bashrc for Bash users

# Add this line:
export JUNIE_TRAM_AI_API_KEY="<your-tram-ai-api-key>"
```

Sau khi lưu, khởi động lại terminal hoặc chạy `source ~/.zshrc` để các thay đổi có hiệu lực.

#### Inline

Bạn cũng có thể truyền API key trực tiếp khi chạy Junie:

**`lines`**

```bash lines
junie --tram-ai-api-key "<your-tram-ai-api-key>"
```

#### CI/CD

Trong các pipeline CI/CD, hãy đặt biến môi trường trong cấu hình runner của bạn:

**`lines`**

```bash lines
export JUNIE_TRAM_AI_API_KEY="<your-tram-ai-api-key>"
junie "Review and fix any code quality issues in the latest commit"
```

> **Note**
>
> Thay `<your-tram-ai-api-key>` bằng API key Trạm AI thực tế, lấy từ [trang API Keys](https://console.tramlabs.io/keys). Key sẽ bắt đầu bằng `tram_sk-`.

### Bước 3: Bắt đầu code

Chuyển đến thư mục dự án và khởi động Junie:

**`lines`**

```bash lines
cd /path/to/your/project
junie
```

Nhập prompt trong giao diện CLI tương tác:

**`lines`**

```text lines
> give me an overview of this codebase
```

Dùng `@` để đính kèm file hoặc thư mục vào ngữ cảnh của request, và gõ `/` để xem các slash command khả dụng.

### Chế độ Headless (CI/CD)

Junie hỗ trợ chế độ headless để chạy phi tương tác trong các pipeline CI/CD. Kết hợp với Trạm AI, chế độ này cho phép quản lý chi phí tập trung và truy cập model cho các tác vụ coding tự động:

**`lines`**

```bash lines
# Install Junie CLI
curl -fsSL https://junie.jetbrains.com/install.sh | bash

# Run Junie with Tram AI in headless mode
export JUNIE_TRAM_AI_API_KEY="$TRAM_AI_API_KEY"
junie "Review and fix any code quality issues in the latest commit"
```

#### Ví dụ GitHub Actions

**`lines`**

```yaml lines
name: Code Review
on:
  pull_request:
    types: [opened, synchronize]
jobs:
  review:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
      issues: write
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 1
      - uses: JetBrains/junie-github-action@v0
        with:
          openrouter_api_key: ${{ secrets.TRAM_AI_API_KEY }}
          prompt: "code-review"
```

#### Ví dụ GitLab CI/CD

Làm theo\
[hướng dẫn thiết lập](https://junie.jetbrains.com/docs/junie-gitlab-ci-cd.html)\
để cấu hình dự án Junie Workspace, sau đó thêm\
`JUNIE_TRAM_AI_API_KEY` làm biến CI/CD. Sau khi\
thiết lập xong, kích hoạt việc review bằng cách bình luận trên bất kỳ MR nào:

**`lines`**

```text lines
#junie code-review
```

### Xác minh kết nối

Sau khi bắt đầu một phiên làm việc, hãy mở [Activity Dashboard của Trạm AI](https://console.tramlabs.io/settings/logs) để xác nhận request đang được route qua Trạm AI.

### Tìm hiểu thêm

* **Tài liệu Junie CLI**: [junie.jetbrains.com/docs](https://junie.jetbrains.com/docs/junie-cli.html)
* **Biến môi trường của Junie**: [Tài liệu tham khảo biến môi trường](https://junie.jetbrains.com/docs/environment-variables.html)
* **Bắt đầu nhanh với Trạm AI**: [Bắt đầu với Trạm AI](https://tram-ai.docs.buildwithfern.com/bat-dau-nhanh)
* **Các model khả dụng**: [Duyệt model Trạm AI](https://tramlabs.io/models)