# Qwen Code

> Connect Qwen Code to HeyEly by adding an OpenAI-compatible provider entry in settings.json.

Qwen Code loads custom endpoints from the `modelProviders` block inside `settings.json`. Its `openai` provider speaks Chat Completions, so point `baseUrl` at the root `https://heyely.si/v1` rather than a full endpoint path.

## Set up

1. Create a key in [Developers](https://heyely.si/keys) and either export `HEYELY_API_KEY` in your shell or add `HEYELY_API_KEY=sk-df-...` to `~/.qwen/.env`.
2. Add the HeyEly provider configuration to `~/.qwen/settings.json` (or `%USERPROFILE%\.qwen\settings.json` on Windows).

```json
{
  "modelProviders": {
    "openai": [
      {
        "id": "anthropic/claude-sonnet-5.5",
        "name": "Claude Sonnet 5.5 (HeyEly)",
        "baseUrl": "https://heyely.si/v1",
        "envKey": "HEYELY_API_KEY",
        "generationConfig": {
          "contextWindowSize": 1000000,
          "samplingParams": { "max_tokens": 128000 }
        }
      }
    ]
  },
  "security": { "auth": { "selectedType": "openai" } },
  "model": { "name": "anthropic/claude-sonnet-5.5" }
}
```

3. Launch `qwen`.

Avoid placing raw secrets inside `settings.json`'s `env` block or passing `--openai-api-key` on the command line where they can leak into history or logs. Using `envKey` keeps the credential safely in your environment.

## Verify

1. Start a session and run `/doctor` to check auth and environment loading.
2. Run `/model` to confirm your HeyEly model is listed.
3. Fire off a quick CLI smoke test:

```bash
qwen -m anthropic/claude-sonnet-5.5 -p "Reply with exactly: gateway-ok"
```

4. Check [Credit and usage](https://heyely.si/usage) to see the request at the top of **Spend** under your selected model.

## Pick a model

* Select your active model via `/model`, `-m`, or `model.name` in `settings.json`.
* Always nest token limits inside each entry's `generationConfig`; top-level `model.generationConfig` settings do not apply to custom providers.
* Want to route an entry to `POST /v1/responses` instead of the default `chat-completions`? Add `"wireApi": "responses"` to that model object.
* Updates to `modelProviders` take effect live without restarting Qwen Code.

## Troubleshooting

| You see                            | Cause                                                                | Fix                                                              |
| ---------------------------------- | -------------------------------------------------------------------- | ---------------------------------------------------------------- |
| `401 invalid_api_key`              | `HEYELY_API_KEY` is missing in Qwen Code's environment               | Export it in the launch shell or save it in `~/.qwen/.env`       |
| Model missing from `/model`        | Wrong provider key or entry wrapped in an object instead of an array | Place entries directly in an array under `modelProviders.openai` |
| Qwen Code prompts for Qwen sign-in | `selectedType` was not switched                                      | Set `security.auth.selectedType` to `"openai"`                   |
| `404`                              | `baseUrl` includes an extra path or omits `/v1`                      | Set `baseUrl` to `https://heyely.si/v1`                          |
| `404 model_not_found`              | `id` does not match HeyEly's catalog                                 | Copy the exact ID from the Models page                           |
