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

# OpenRouter Configuration

> Access 100+ AI models through OpenRouter in Glyph

OpenRouter provides unified API access to 100+ AI models from multiple providers including OpenAI, Anthropic, Google, Meta, and more.

## Prerequisites

* OpenRouter account: [openrouter.ai](https://openrouter.ai)
* API key (free credits available)
* Credits for paid models (or use free models)

## Setup

<Steps>
  <Step title="Get API Key">
    1. Sign up at [openrouter.ai](https://openrouter.ai)
    2. Navigate to **Keys** in your account
    3. Click **Create Key**
    4. Copy the key (starts with `sk-or-`)

    <Note>
      OpenRouter provides \$1 in free credits to test models.
    </Note>
  </Step>

  <Step title="Open Glyph AI Settings">
    Go to **Settings → AI** and select the **OpenRouter** profile.
  </Step>

  <Step title="Add API Key">
    1. Click **Set API Key** in the authentication section
    2. Paste your OpenRouter API key
    3. Click **Save**

    The key is stored in `.glyph/app/ai_secrets.json` in your space directory.
  </Step>

  <Step title="Select Model">
    Click the **Model** dropdown. Glyph fetches 100+ available models from OpenRouter.

    Popular models:

    * `anthropic/claude-3.5-sonnet`
    * `openai/gpt-4o`
    * `google/gemini-pro-1.5`
    * `meta-llama/llama-3.1-70b-instruct`
    * `mistralai/mistral-large`

    <Note>
      Free models are marked in the OpenRouter model list.
    </Note>
  </Step>

  <Step title="Test Connection">
    Open the AI panel and send a test message. You should receive a response from your selected model.
  </Step>
</Steps>

## Configuration

### Provider Settings

* **Service**: `openrouter`
* **Base URL**: `https://openrouter.ai/api/v1` (default)
* **Authentication**: Bearer token (API key)

### Model Routing

OpenRouter automatically routes your request to the best available provider for your selected model.

## Model Selection

Glyph fetches the latest model list from OpenRouter's `/v1/models` endpoint.

### Model Details

OpenRouter provides rich model metadata:

* **Context length** - Maximum tokens per request
* **Pricing** - Input and output token costs
* **Modalities** - Text, image, audio support
* **Max output tokens** - Maximum response length
* **Supported parameters** - Available model options

Hover over the info icon in the model selector to view these details.

### Recommended Models

#### Free Models

| Model                                   | Provider | Use Case        |
| --------------------------------------- | -------- | --------------- |
| `meta-llama/llama-3.1-8b-instruct:free` | Meta     | General purpose |
| `mistralai/mistral-7b-instruct:free`    | Mistral  | Fast tasks      |
| `google/gemini-flash-1.5:free`          | Google   | Multimodal      |

<Note>
  Free models have rate limits but are great for testing and light usage.
</Note>

#### Paid Models (High Performance)

| Model                               | Input Cost       | Output Cost      |
| ----------------------------------- | ---------------- | ---------------- |
| `anthropic/claude-3.5-sonnet`       | \$3/1M tokens    | \$15/1M tokens   |
| `openai/gpt-4o`                     | \$2.50/1M tokens | \$10/1M tokens   |
| `google/gemini-pro-1.5`             | \$1.25/1M tokens | \$5/1M tokens    |
| `meta-llama/llama-3.1-70b-instruct` | \$0.88/1M tokens | \$0.88/1M tokens |

Check current pricing at [openrouter.ai/models](https://openrouter.ai/models).

## Features

### Chat Mode

Conversational interaction:

* Back-and-forth dialogue with any model
* No file system access
* Fast responses
* Best for discussion and brainstorming

### Create Mode

AI with workspace tools:

* **read\_file** - Read files from your space
* **search\_notes** - Search note content
* **list\_dir** - List directory contents
* Tool usage tracked in timeline view
* Best for research and knowledge retrieval

<Note>
  Tool support varies by model. Most modern models (GPT-4, Claude, Gemini) support function calling.
</Note>

### Context Attachment

Attach notes for grounded responses:

* Attach files or folders via context menu
* Mention with `@filename` syntax
* Configure character budget (up to 250K chars)
* Context limits vary by model

## API Usage and Billing

### Credits

OpenRouter uses a credit system:

* 1 credit = \$1 USD
* Purchase credits at [openrouter.ai/credits](https://openrouter.ai/credits)
* Free credits on signup

### Cost Estimation

Use the model selector to view pricing before sending:

1. Select a model
2. Hover over the info icon
3. View input/output pricing
4. Estimate cost: (input\_tokens × input\_price) + (output\_tokens × output\_price)

### Rate Limits

Rate limits depend on your credit balance and model:

* Higher credit balance = higher rate limits
* Free models have stricter limits
* Check limits at [openrouter.ai/docs/limits](https://openrouter.ai/docs/limits)

## Troubleshooting

### "API key not set for this profile"

**Solution**: Add your OpenRouter API key in Settings → AI.

### "model list failed (401)"

**Solution**: Your API key is invalid. Generate a new key from OpenRouter.

### "insufficient credits"

**Solution**: Add credits at [openrouter.ai/credits](https://openrouter.ai/credits) or use a free model.

### "model not found"

**Cause**: The model ID is incorrect or the model is no longer available.

**Solution**: Refresh the model list or check [openrouter.ai/models](https://openrouter.ai/models) for valid model IDs.

### Model list is very long

**Solution**: Use the search/filter in the model selector. Type to filter by provider or model name.

### Responses from different providers

**Cause**: OpenRouter routes to the best available provider for your model. If primary provider is unavailable, it uses a fallback.

**Solution**: This is expected behavior. Check OpenRouter's dashboard for routing details.

## Advanced Features

### Provider Preferences

Some OpenRouter models allow provider selection (e.g., `anthropic/claude-3.5-sonnet:beta` vs `anthropic/claude-3.5-sonnet`).

Use the full model ID from [openrouter.ai/models](https://openrouter.ai/models) to specify routing.

### Custom Headers

OpenRouter supports custom headers for advanced use cases:

```json theme={null}
[
  { "key": "HTTP-Referer", "value": "https://yourdomain.com" },
  { "key": "X-Title", "value": "Glyph Integration" }
]
```

These headers may provide better rate limits and routing.

## Security Best Practices

<Warning>
  * Never commit `.glyph/app/ai_secrets.json` to version control
  * Rotate API keys if exposed
  * Monitor usage at [openrouter.ai/activity](https://openrouter.ai/activity)
  * Set spending limits in your OpenRouter account
</Warning>

## OpenRouter vs Direct Providers

### Advantages of OpenRouter

✅ Single API key for 100+ models
✅ Automatic provider failover
✅ Unified billing
✅ Model comparison and discovery
✅ Free models available

### When to Use Direct Providers

* Lower latency (no routing layer)
* Provider-specific features (e.g., Anthropic's thinking models)
* Direct billing relationship
* Higher rate limits with provider-native keys

## Next Steps

<CardGroup cols={2}>
  <Card title="Chat Modes" icon="messages" href="/ai/chat-modes">
    Learn about chat vs create modes
  </Card>

  <Card title="Context Management" icon="folder" href="/ai/context-management">
    Attach notes to conversations
  </Card>

  <Card title="OpenAI" icon="brain" href="/ai/providers/openai">
    Compare with direct OpenAI integration
  </Card>

  <Card title="Profiles" icon="user-group" href="/ai/profiles">
    Manage multiple AI profiles
  </Card>
</CardGroup>
