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

> Connect Opsh to OpenAI, Anthropic, Gemini, OpenRouter, or a local Ollama model. Configure API keys, base URLs, and active provider.

# AI Setup

Opsh works with five AI providers: OpenAI, Anthropic, Gemini, OpenRouter, and Ollama. All provider settings live in `~/.opsh/config.json` under the `provider` key. Only the provider named in `provider.selected` is used at runtime — the others retain their settings so you can switch between them without re-entering credentials.

## Setting your provider interactively

The easiest way to configure a provider is through the interactive editor:

* Run `opsh --init` in your terminal to open the setup wizard.
* Type `!config` inside the Opsh REPL, then choose **Provider** from the menu.

Both flows let you pick a provider, choose a model, and enter your API key. Your selections are saved to `~/.opsh/config.json` immediately.

## The `provider.selected` field

The `provider.selected` field controls which provider Opsh uses. Set it to one of:

| Value          | Provider               |
| -------------- | ---------------------- |
| `"openrouter"` | OpenRouter             |
| `"openai"`     | OpenAI API             |
| `"anthropic"`  | Anthropic API          |
| `"gemini"`     | Gemini (Google AI API) |
| `"ollama"`     | Ollama (local)         |

## Provider config snippets

Each provider has its own sub-object inside `provider`. The tabs below show the full structure and default values for each one.

<Tabs>
  <Tab title="OpenRouter">
    ```json config.json theme={null}
    {
      "provider": {
        "selected": "openrouter",
        "openrouter": {
          "model": "openrouter/auto",
          "baseUrl": "https://openrouter.ai/api/v1",
          "apiKey": "YOUR_OPENROUTER_KEY",
          "temperature": 0.1
        }
      }
    }
    ```

    | Field         | Description                                                       |
    | ------------- | ----------------------------------------------------------------- |
    | `model`       | Model ID to use. Default: `openrouter/auto`.                      |
    | `baseUrl`     | OpenRouter API endpoint. Default: `https://openrouter.ai/api/v1`. |
    | `apiKey`      | Your OpenRouter API key.                                          |
    | `temperature` | Sampling temperature (0–1). Default: `0.1`.                       |
  </Tab>

  <Tab title="OpenAI">
    ```json config.json theme={null}
    {
      "provider": {
        "selected": "openai",
        "openai": {
          "model": "gpt-5.1",
          "baseUrl": "https://api.openai.com/v1",
          "apiKey": "YOUR_OPENAI_KEY",
          "temperature": 0.1
        }
      }
    }
    ```

    | Field         | Description                                                |
    | ------------- | ---------------------------------------------------------- |
    | `model`       | Model ID to use. Default: `gpt-5.1`.                       |
    | `baseUrl`     | OpenAI API endpoint. Default: `https://api.openai.com/v1`. |
    | `apiKey`      | Your OpenAI API key.                                       |
    | `temperature` | Sampling temperature (0–1). Default: `0.1`.                |
  </Tab>

  <Tab title="Anthropic">
    ```json config.json theme={null}
    {
      "provider": {
        "selected": "anthropic",
        "anthropic": {
          "model": "claude-sonnet-4-20250514",
          "baseUrl": "https://api.anthropic.com/v1",
          "apiKey": "YOUR_ANTHROPIC_KEY",
          "temperature": 0.1,
          "apiVersion": "2023-06-01",
          "maxTokens": 1200
        }
      }
    }
    ```

    | Field         | Description                                                      |
    | ------------- | ---------------------------------------------------------------- |
    | `model`       | Model ID to use. Default: `claude-sonnet-4-20250514`.            |
    | `baseUrl`     | Anthropic API endpoint. Default: `https://api.anthropic.com/v1`. |
    | `apiKey`      | Your Anthropic API key.                                          |
    | `temperature` | Sampling temperature (0–1). Default: `0.1`.                      |
    | `apiVersion`  | Anthropic API version header. Default: `2023-06-01`.             |
    | `maxTokens`   | Maximum tokens in the response. Default: `1200`.                 |
  </Tab>

  <Tab title="Gemini">
    ```json config.json theme={null}
    {
      "provider": {
        "selected": "gemini",
        "gemini": {
          "model": "gemini-2.5-flash",
          "baseUrl": "https://generativelanguage.googleapis.com/v1beta",
          "apiKey": "YOUR_GEMINI_KEY",
          "temperature": 0.1
        }
      }
    }
    ```

    | Field         | Description                                                                          |
    | ------------- | ------------------------------------------------------------------------------------ |
    | `model`       | Model ID to use. Default: `gemini-2.5-flash`.                                        |
    | `baseUrl`     | Google AI API endpoint. Default: `https://generativelanguage.googleapis.com/v1beta`. |
    | `apiKey`      | Your Google AI API key.                                                              |
    | `temperature` | Sampling temperature (0–1). Default: `0.1`.                                          |
  </Tab>

  <Tab title="Ollama">
    ```json config.json theme={null}
    {
      "provider": {
        "selected": "ollama",
        "ollama": {
          "model": "qwen3-coder",
          "baseUrl": "http://localhost:11434/api",
          "temperature": 0.1
        }
      }
    }
    ```

    | Field         | Description                                               |
    | ------------- | --------------------------------------------------------- |
    | `model`       | Model tag to use. Default: `qwen3-coder`.                 |
    | `baseUrl`     | Ollama server URL. Default: `http://localhost:11434/api`. |
    | `temperature` | Sampling temperature (0–1). Default: `0.1`.               |

    <Tip>
      Ollama runs locally on your machine and does not require an API key. Make sure Ollama is installed and the model you want is pulled (`ollama pull <model>`) before running Opsh.
    </Tip>
  </Tab>
</Tabs>

## Default base URLs

| Provider   | Default base URL                                   |
| ---------- | -------------------------------------------------- |
| OpenRouter | `https://openrouter.ai/api/v1`                     |
| OpenAI     | `https://api.openai.com/v1`                        |
| Anthropic  | `https://api.anthropic.com/v1`                     |
| Gemini     | `https://generativelanguage.googleapis.com/v1beta` |
| Ollama     | `http://localhost:11434/api`                       |

You can change `baseUrl` to point to a compatible proxy or self-hosted endpoint.

<Note>
  API keys are stored as plain text in `~/.opsh/config.json`. Restrict access to this file so other users on the system cannot read it:

  ```bash theme={null}
  chmod 600 ~/.opsh/config.json
  ```
</Note>
