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

# Kimi Provider

> Moonshot AI K2/K2.5 models via OAuth (CLIProxy) or API key direct (km)

# Kimi Provider

CCS provides two distinct Kimi offerings:

| Command    | Auth                             | Endpoint                                  | Use Case                         |
| ---------- | -------------------------------- | ----------------------------------------- | -------------------------------- |
| `ccs kimi` | OAuth via CLIProxy (device code) | `http://127.0.0.1:8317/api/provider/kimi` | Multi-account, no API key needed |
| `ccs km`   | API key direct                   | `https://api.kimi.com/coding/`            | Single API key, Kimi for Coding  |

Provider aliases: `kimi`, `moonshot` both route to the same CLIProxy provider.

## Quick Start

```bash theme={null}
# OAuth mode (CLIProxy) — no API key needed
ccs kimi "explain this code"

# API preset mode — requires API key (Kimi for Coding)
ccs km "explain this code"

# List accounts (OAuth mode)
ccs kimi --accounts

# Switch account
ccs kimi --use work
```

## Authentication

### `ccs kimi` — OAuth Mode (CLIProxy)

<Steps>
  <Step title="Trigger Login">
    Run `ccs kimi --kimi-login` — device code displayed in terminal
  </Step>

  <Step title="Activate Device">
    Visit the URL shown and enter the device code (no callback port needed)
  </Step>

  <Step title="Token Cached">
    OAuth token saved to `~/.ccs/cliproxy/auth/kimi-{email}.json`
  </Step>

  <Step title="Auto Refresh">
    CLIProxy backend manages token refresh automatically
  </Step>
</Steps>

**Device Code Flow:** Polling-based authentication — no local callback server required. Works in headless/server environments.

### `ccs km` — API Key Mode (Kimi for Coding)

<Steps>
  <Step title="Get API Key">
    Obtain a `sk-...` key from Moonshot AI platform
  </Step>

  <Step title="Configure">
    Run `ccs km` — prompted for API key on first use
  </Step>

  <Step title="Thinking Always On">
    All requests use extended thinking by default
  </Step>
</Steps>

<Note>
  `ccs km` connects directly to `https://api.kimi.com/coding/`. Default model: `kimi-for-coding`. The `--preset kimi` flag auto-maps to `km` for backward compatibility.
</Note>

## Multi-Account Support

<Tabs>
  <Tab title="Add Account">
    ```bash theme={null}
    # Add second Kimi account (preserves existing)
    ccs kimi --kimi-login --add

    # Auto-nicknamed from email prefix
    ```
  </Tab>

  <Tab title="List Accounts">
    ```bash theme={null}
    ccs kimi --accounts

    # Output:
    # Available Kimi accounts:
    # * personal (user@email.com) - default
    #   work (work@email.com)
    ```
  </Tab>

  <Tab title="Switch Account">
    ```bash theme={null}
    # Switch default account
    ccs kimi --use work

    # Rename current account
    ccs kimi --nickname personal
    ```
  </Tab>
</Tabs>

**Account Registry:** `~/.ccs/cliproxy/accounts.json` — aliases `kimi` and `moonshot` both map to the same provider.

## Model Configuration

### Available Models

#### `ccs kimi` (CLIProxy OAuth)

| Model              | Context | Notes                       |
| ------------------ | ------- | --------------------------- |
| `kimi-k2.5`        | 262K    | Default — latest multimodal |
| `kimi-k2-thinking` | —       | Extended reasoning          |
| `kimi-k2`          | —       | Flagship coding model       |

#### `ccs km` (API key direct)

| Model             | Notes                  |
| ----------------- | ---------------------- |
| `kimi-for-coding` | Default model for `km` |

**Thinking budget:** 1K–32K tokens, dynamic and zero allowed.

**Vision:** Configurable via `vision-model` placeholder in settings.

### Settings Template

Settings saved to `~/.ccs/km.settings.json` from `base-km.settings.json`:

```json theme={null}
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.kimi.com/coding/",
    "ANTHROPIC_AUTH_TOKEN": "YOUR_KIMI_API_KEY_HERE",
    "ANTHROPIC_MODEL": "kimi-for-coding",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "kimi-for-coding",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "kimi-for-coding",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "kimi-for-coding"
  }
}
```

<Note>
  These env vars are injected automatically by CCS. Manual override is rarely needed.
</Note>

## Commands Reference

```bash theme={null}
# Basic usage
ccs kimi "your prompt"
ccs km "your prompt"              # API preset

# Authentication
ccs kimi --kimi-login             # Trigger device code OAuth
ccs kimi --kimi-login --add       # Add second account
ccs kimi --logout                 # Clear tokens

# Account management
ccs kimi --accounts               # List all accounts
ccs kimi --use work               # Switch default account
ccs kimi --nickname personal      # Rename current account
```

## Troubleshooting

### Device Code Expired

**Symptom:** "Device code expired" error during login

**Solution:** Device codes have a short TTL. Re-run login and complete quickly:

```bash theme={null}
ccs kimi --logout
ccs kimi --kimi-login
```

### API Key Rejected (km mode)

**Symptom:** 401 errors when using `ccs km`

**Solution:** Verify key format (`sk-...`) and permissions on Moonshot AI platform.

<Warning>
  API keys for `ccs km` are separate from OAuth tokens used by `ccs kimi`. Do not mix them.
</Warning>

### Wrong Account Active

**Symptom:** Unexpected account being used

**Solution:**

```bash theme={null}
# Check default (marked with *)
ccs kimi --accounts

# Switch default
ccs kimi --use work
```

## Storage Locations

| Path                               | Description                    |
| ---------------------------------- | ------------------------------ |
| `~/.ccs/cliproxy/auth/kimi-*.json` | OAuth tokens (one per account) |
| `~/.ccs/cliproxy/accounts.json`    | Account registry, nicknames    |
| `~/.ccs/km.settings.json`          | Kimi for Coding model config   |

## Cost Information

| Model              | Input/M | Output/M | Cache/M |
| ------------------ | ------- | -------- | ------- |
| `kimi-k2.5`        | \$0.60  | \$3.00   | \$0.10  |
| `kimi-k2-thinking` | \$0.60  | \$2.50   | \$0.15  |
| `kimi-for-coding`  | \$0.60  | \$2.50   | \$0.15  |
| `kimi-k2`          | \$0.60  | \$2.50   | \$0.15  |

## Next Steps

<CardGroup cols={2}>
  <Card title="Multi-Account Setup" icon="users" href="/providers/concepts/overview#multi-account-management">
    Manage multiple Kimi accounts
  </Card>

  <Card title="API Preset (km)" icon="key" href="/providers/concepts/overview#api-presets">
    Configure direct API key access
  </Card>

  <Card title="Remote Proxy" icon="server" href="/features/proxy/remote-proxy">
    Connect to external CLIProxy server
  </Card>

  <Card title="All Providers" icon="grid" href="/providers/concepts/overview">
    Explore other supported providers
  </Card>
</CardGroup>
