# Add a provider connection.

> A model connection (`ai`: its harness, and optionally its default model; a launch always names its model) or the workspace's Boat account.
> https://koi.dog/docs/api/provider-connections/create-provider-connection/

`POST /api/v1/provider-connections` · Scope: `config`

Its key goes to `setConnectionSecret` (a model connection) or `setCloudApiKey` (Boat) afterwards; it is never part of this body. OpenCode's own service (`provider: "opencode"`, harness `opencode`) takes no key at all: `method: "free"` is its free models (workspace scope; once per workspace, so adding it again answers the one there), usable on any machine that runs OpenCode, cloud workers included; `method: "machine_sign_in"` is the OpenCode account a paired machine is signed in to (`opencode auth login` there), with `scope: { kind: "machine", nodeId }` and placement `local`: only the person who paired that machine may add it (`403 not_allowed`; never with an API key), it is theirs (`owner`), runs only there and only for crews they launch, never on a cloud worker (`400 invalid_body`), and once per machine and person. Their account check reads what machines report, never a paid turn. The timeline records the key ID, action and outcome.

## Headers.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | no | Retry the same request with the same key. [Retry rules](https://koi.dog/docs/api/#retries). |

## Body.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `provider` | `enum` | yes | Who serves the model, or `boat` for the workspace's Boat account. `opencode-zen` and `opencode-go` run on the OpenCode harness only. One of `anthropic`, `morph`, `openai`, `custom`, `opencode-zen`, `opencode-go`, `opencode`, `boat`. |
| `method` | `enum` | yes | How it signs in. Boat and OpenCode take `api_key`; `boat_profile` is for OpenAI through Codex. One of `api_key`, `oauth_token`, `boat_profile`, `free`, `machine_sign_in`. |
| `name` | `string` | yes | A name for the connection, shown in the dashboard. 1 to 80 characters. |
| `scope` | `object` | yes | Who may use it. A new model connection is workspace-wide (`409 method_unavailable` for a project or a machine); Boat is always workspace-wide. |
| `scope.kind` | `enum` | yes | `workspace` for the whole workspace, `project` for one project, `machine` for one paired machine. |
| `scope.projectId` | `string` | no | The project, when `kind` is `project`. At least 5 characters. With `kind` `project`. |
| `scope.nodeId` | `string` | no | The machine, when `kind` is `machine`. At least 5 characters. With `kind` `machine`. |
| `placement` | `enum` | yes | Where it may run: `local` on paired machines, `cloud` on cloud workers, `both`. |
| `ai` | `object` | no | The model settings, required for every provider but Boat, which takes none. |
| `ai.harness` | `enum` | yes | The coding agent program that runs the model. A machine runs it only when that harness is installed there. One of `claude-code`, `pi`, `codex`, `opencode`. |
| `ai.model` | `string` | no | The model agents use when a launch names none. Optional: a launch always names its model. 1 to 200 characters. |
| `ai.options` | `object` | no | Options agents use when a launch names none. Default `{}`. |
| `ai.options.effort` | `enum` | no | How hard the model thinks, where the harness and model take it. One of `low`, `medium`, `high`, `xhigh`, `max`. |
| `ai.baseUrl` | `string` | no | The provider's address, for a `custom` provider only. A URL. |
| `ai.metering` | `enum` | yes | How you pay the provider for it: `subscription` or `metered`. Shown in forecasts; Koidog bills nothing. |
| `ai.maxConcurrent` | `1–100` | yes | The most agents that use it at once; the rest wait. |
| `cloudSpendCap` | `object \| null` | no | The cloud spend cap offered at Boat connect: a monthly amount, or null to skip (asked before the first cloud spend). |
| `cloudSpendCap.capUsd` | `number` | no | The most the workspace may spend on cloud VMs in a calendar month (UTC), in US dollars. A launch that would go over it is refused before a VM is created. > 0. ≤ 1000000. Default `10`. |
| `cloudSpendCap.period` | `"month"` | no | How often the cap starts again. Only `month` today. Default `month`. |

## Response.

201 Created · JSON object

- **422 validation_failed**: Each schema error appears in `details`.

## Request.

```sh
curl -X POST https://api.koi.dog/api/v1/provider-connections \
    -H "Authorization: Bearer $KOIDOG_API_KEY" \
    -H "Idempotency-Key: $(uuidgen)" \
    -H "Content-Type: application/json" \
    -d '{
      "provider": "anthropic",
      "method": "api_key",
      "name": "Claude",
      "scope": {
        "kind": "workspace"
      },
      "placement": "both",
      "ai": {
        "harness": "claude-code",
        "metering": "metered",
        "maxConcurrent": 4
      }
    }'
```

```js
const res = await fetch("https://api.koi.dog/api/v1/provider-connections", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KOIDOG_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    provider: "anthropic",
    method: "api_key",
    name: "Claude",
    scope: {
      kind: "workspace",
    },
    placement: "both",
    ai: {
      harness: "claude-code",
      metering: "metered",
      maxConcurrent: 4,
    },
  }),
});
console.log(await res.json());
```

```python
import os
import uuid

import requests

r = requests.post(
    "https://api.koi.dog/api/v1/provider-connections",
    headers={
        "Authorization": f"Bearer {os.environ['KOIDOG_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "provider": "anthropic",
        "method": "api_key",
        "name": "Claude",
        "scope": {
            "kind": "workspace",
        },
        "placement": "both",
        "ai": {
            "harness": "claude-code",
            "metering": "metered",
            "maxConcurrent": 4,
        },
    },
)
r.raise_for_status()
print(r.json())
```

## Response example.

```json
{
  "status": "not_connected",
  "reason": "not_configured",
  "next": [],
  "id": "string",
  "name": "string",
  "provider": "anthropic",
  "method": "api_key",
  "payer": "own",
  "scope": {
  },
  "owner": {
  },
  "placement": "local",
  "base": "unconfigured",
  "generation": 0,
  "holds": [],
  …
}
```
