# KimiCodeProvider

A [pi-coding-agent](https://github.com/mariozechner/pi-coding-agent) extension that adds support for **Kimi Code API** (Moonshot's coding-optimized API endpoint).

This extension registers a `moonshot` provider with all available Kimi models, allowing you to use Kimi's coding API with configurable base URL and User-Agent.

## Installation

```bash
pi install npm:kimicodeprovider
```

For project-local installation:
```bash
pi install npm:kimicodeprovider -l
```

## Configuration

### 1. API Key (Required)

Set your Moonshot API key as an environment variable:

```bash
export MOONSHOT_API_KEY="your-api-key-here"
```

Add this to your shell profile (`~/.bashrc`, `~/.zshrc`, etc.) to make it persistent.

### 2. Start Using Kimi Models

Once installed and the API key is set, restart pi and the Kimi models will appear in the model selector:

```bash
pi
```

Then press `Ctrl+L` to open the model selector and choose any Kimi model.

Or specify directly via command line:

```bash
pi --provider moonshot --model kimi-for-coding
```

## Available Models

After installation, these models will be available in pi:

| Model | Best For | Context | Max Tokens | Reasoning | Vision |
|-------|----------|---------|------------|-----------|--------|
| `kimi-for-coding` | **Coding tasks** | 262K | 32K | Yes | No |
| `kimi-k2.5` | Multimodal + reasoning | 262K | 32K | Yes | Yes |
| `kimi-latest` | Latest general model | 131K | 131K | No | Yes |
| `kimi-k2-turbo-preview` | Fast responses | 262K | 32K | No | No |
| `kimi-k2-thinking` | Deep reasoning | 262K | 32K | Yes | No |
| `moonshot-v1-8k` | Legacy V1 series | 8K | 8K | No | No |
| `moonshot-v1-32k` | Legacy V1 series | 32K | 32K | No | No |
| `moonshot-v1-128k` | Legacy V1 series | 128K | 128K | No | No |

## Advanced Configuration

### Custom Base URL

By default, this extension uses the **Kimi Code API endpoint**: `https://api.kimi.com/coding/v1`

To use a custom endpoint (e.g., proxy or enterprise deployment):

```bash
export KIMI_BASE_URL="https://your-custom-endpoint.com/coding"
```

The extension automatically handles URL formatting:
- If URL ends with `/coding`, it appends `/v1`
- If URL ends with `/coding/`, it appends `v1`

### Custom User-Agent

```bash
export KIMI_USER_AGENT="YourApp/1.0"
```

Default: `KimiCLI/1.3`

## Environment Variables

| Variable | Required | Default | Description |
|----------|----------|---------|-------------|
| `MOONSHOT_API_KEY` | **Yes** | - | Your Moonshot API key |
| `KIMI_BASE_URL` | No | `https://api.kimi.com/coding/v1` | Custom API base URL |
| `KIMI_USER_AGENT` | No | `KimiCLI/1.3` | Request User-Agent header |

## Troubleshooting

**Kimi models not showing in selector:**
- Run `/reload` in pi to refresh extensions
- Verify the extension is installed: `pi list`
- Check that `MOONSHOT_API_KEY` is set: `echo $MOONSHOT_API_KEY`

**API errors:**
- Verify your API key is valid at [Moonshot Platform](https://platform.moonshot.cn/)
- Check if your base URL is accessible
- For custom endpoints, ensure they support the OpenAI-compatible API format

## Uninstall

```bash
pi remove npm:kimicodeprovider
```

## About Kimi Code API

This extension connects to Moonshot's **Kimi Code API** (`api.kimi.com/coding/v1`), which is optimized for coding tasks and provides access to the latest Kimi models including the `kimi-for-coding` model specifically fine-tuned for software development.

Learn more: [Moonshot Platform](https://platform.moonshot.cn/)

## License

MIT
