# Kilo CLI Integration

AVELIN API works with [Kilo CLI](https://kilocode.ai) — the command-line client for Kilo Code. Kilo CLI connects directly to AVELIN and provides terminal-based AI coding assistance with file operations, command execution, and multi-step task automation.

> **Why AVELIN + Kilo CLI?** Get access to frontier coding models through Kilo's terminal interface with 1M-token context windows, automatic failover, and competitive pricing.

---

## Quick Setup

### Step 1: Get your AVELIN API key

Sign up at [avelin.ai](https://avelin.ai) and generate an API key. It will look like `sk-ave...xxxx`.

### Step 2: Install Kilo CLI

**Prerequisites:** Install [Node.js](https://nodejs.org/en/download/) (v18.0 or later).

```bash
npm install -g @kilocode/cli
kilo --version
```

If a version number displays, the installation was successful.

### Step 3: Configure Kilo CLI

Create the configuration file at `~/.config/kilo/config.json`:

```json
{
  "$schema": "https://kilo.ai/config.json",
  "provider": {
    "avelin": {
      "npm": "@ai-sdk/anthropic",
      "name": "AVELIN AI",
      "options": {
        "baseURL": "https://api.avelin.ai",
        "apiKey": "sk-a...
      },
      "models": {
        "avelin-coding-pro": {
          "name": "Avelin Coding Plus",
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 32768
            }
          }
        },
        "avelin-coding-fast": {
          "name": "Avelin Coding",
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 32768
            }
          }
        },
        "avelin-coding-ultra": {
          "name": "Avelin Coding Architect",
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 32768
            }
          }
        },
        "avelin-fast": {
          "name": "Avelin Fast"
        }
      }
    }
  }
}
```

### Step 4: Start Kilo CLI

```bash
kilo
```

Kilo CLI will automatically use AVELIN as the backend.

---

## Recommended Models

### Primary Recommendation: `avelin-coding-pro`

For everyday coding tasks:

| Feature | avelin-coding-pro | Why it matters for Kilo CLI |
|---|---|---|
| **Context window** | **1M tokens** | Large codebases and multi-file refactors without context loss |
| **Max output** | **65K tokens** | Generate large code files and comprehensive tests |
| **Throughput** | **~100 tokens/sec** | 2× faster than standard tiers — faster feedback loops |
| **Reasoning** | Deep step-by-step thinking | Catches subtle bugs, understands architectural impact |
| **Tool calling** | First-class support | Reliable file operations and command execution |

### Alternative Models

| Model | When to use |
|---|---|
| `avelin-coding-fast` | Lighter coding tasks, quick questions — saves cost on simple work |
| `avelin-coding-ultra` | System design, architecture reviews, security-sensitive refactors |
| `avelin-fast` | Quick lookups and simple extractions — lowest cost, fastest response |

---

## Why AVELIN for Kilo CLI?

### 1. **Cost Optimization**

Kilo CLI sessions can be long with large context windows. AVELIN delivers frontier-tier coding quality at sustainable economics:

- **Prompt caching**: ~80% cost reduction on repeated system prompts
- **Competitive pricing**: Lower per-token costs than direct provider APIs
- **Pay-per-token**: No subscription lock-in

### 2. **Model Diversity**

Access multiple frontier coding models through one API. AVELIN routes your requests to a diverse set of frontier models across multiple cloud providers, ensuring high availability and consistent quality. If one provider is slow or unavailable, your request automatically routes to the next best option.

### 3. **Reliability**

- **Automatic failover**: If one provider is slow or down, AVELIN switches to another
- **Retry logic**: Transient errors are handled automatically
- **99.9% uptime**: Enterprise-grade infrastructure

### 4. **1M Context Windows**

Kilo CLI works best with large context. AVELIN's coding models support 1M tokens — load entire repositories without chunking.

---

## Example Session

```bash
$ kilo

╭─ Kilo CLI ──────────────────────────────────╮
│ Model: avelin-coding-pro                   │
│ Provider: AVELIN (api.avelin.ai)           │
╰─────────────────────────────────────────────╯

You> Refactor the database layer to use the repository pattern.

Kilo: I'll refactor your database layer to use the repository pattern.
      Let me examine the current implementation...

[Reads database files, service layer]

Current state:
- Direct database calls in service files
- No abstraction layer
- Difficult to test and maintain

Here's my plan:
1. Create repository interfaces for each entity
2. Implement repositories with database operations
3. Update services to use repositories instead of direct DB calls
4. Add dependency injection for testability
5. Write tests for repositories and updated services

Shall I proceed?

You> yes

Kilo: [Creates repositories/user.repository.ts]
      [Creates repositories/product.repository.ts]
      [Updates services/user.service.ts]
      [Updates services/product.service.ts]
      [Creates tests/repositories/user.repository.test.ts]
      [Runs tests — all passing]

Done! I've refactored the database layer:
- Created repository interfaces and implementations
- Updated all services to use repositories
- Added dependency injection
- Wrote 15 passing tests

The codebase is now more testable and maintainable.
```

---

## Advanced Configuration

### Multiple Providers

You can configure multiple providers in `~/.config/kilo/config.json`:

```json
{
  "$schema": "https://kilo.ai/config.json",
  "provider": {
    "avelin": {
      "npm": "@ai-sdk/anthropic",
      "name": "AVELIN AI",
      "options": {
        "baseURL": "https://api.avelin.ai",
        "apiKey": "sk-a...
      },
      "models": {
        "avelin-coding-pro": {
          "name": "Avelin Coding Plus",
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 32768
            }
          }
        }
      }
    },
    "avelin-anthropic": {
      "npm": "@ai-sdk/anthropic",
      "name": "AVELIN AI (Anthropic)",
      "options": {
        "baseURL": "https://api.avelin.ai",
        "apiKey": "sk-a...
      },
      "models": {
        "avelin-coding-pro": {
          "name": "Avelin Coding Plus",
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 32768
            }
          }
        }
      }
    }
  }
}
```

### Thinking Budget

The configuration includes `budgetTokens: 32768` for thinking. This allocates tokens for the model's reasoning process:

- **Higher budget** (32K+): Better for complex refactors, architecture decisions
- **Lower budget** (8K): Faster responses for simple edits
- **Disabled**: For quick questions where speed matters most

```json
{
  "avelin-fast": {
    "name": "Avelin Fast",
    "options": {
      "thinking": {
        "type": "disabled"
      }
    }
  }
}
```

### Model Switching

You can switch models on-the-fly in Kilo CLI:

```bash
kilo --model avelin-coding-ultra
```

Or set different models for different tasks in your config.

---

## Troubleshooting

| Issue | Solution |
|---|---|
| **"Provider not found"** | Ensure `@ai-sdk/anthropic` is specified in the npm field |
| **"Model not available"** | Use a valid AVELIN model name from the [Model Catalog](../../models/README.md) |
| **Slow first response** | Normal — model thinks before responding. Streaming starts after reasoning completes. |
| **Context too long errors** | Set `context_length: 1000000` in your configuration |
| **API key errors** | Verify your AVELIN API key is correct and active |

---

## Related

- [API Quickstart](../../api/quickstart.md) — First API call in 5 minutes
- [Hermes Agent Guide](../hermes.md) — Another terminal-based coding tool
- [Claude Code Guide](claude-code.md) — Anthropic's CLI tool
- [OpenCode Guide](opencode.md) — Terminal-based AI coding tool
- [Model Catalog](../../models/README.md) — Full model comparison
- [Kilo Code](https://kilocode.ai) — Official Kilo Code website
