# provider

> A provider block names a provider type with source, sets the attributes that type defines, and gives settings defaults for its agents. Keys are always environment variable names.

A `provider` block declares one configured use of a **provider type**: which driver runs an agent, how to reach the model, and where the key comes from. Agents reference a provider by name (`provider.anthropic`) and pick a model from it, or take the provider's own [`model`](#model). Declare one or more. A swarm can use several providers at once, so one agent can run on Claude and another on a local model.

`source` names the type. Three types are built into Convoy. Any other type is a plugin that its inference provider publishes and convoyd fetches; see [Provider types](/docs/providers/).

## Minimal example

```hcl title="providers.cvy"
provider "anthropic" {
  source = "claude_agent_sdk"
}
```

The key is read from `ANTHROPIC_API_KEY` in convoyd's environment, the type's default.

With `model`, the block also says which model its agents run on, so the agents do not have to:

```hcl title="main.cvy"
provider "llm" {
  source = "claude_agent_sdk"
  model  = "claude-sonnet-5-5"
}

agent "writer" {
  provider = provider.llm              # runs on claude-sonnet-5-5
  prompt   = file("prompts/writer.md")
}
```

## Full example

Three built-in types and one from a repository:

```hcl title="providers.cvy"
provider "anthropic" {
  source   = "claude_agent_sdk"
  api_key  = "ANTHROPIC_API_KEY"
  settings = { effort = "high" }           # default for every agent on this provider
}

provider "openai" {
  source  = "openai_agents"
  api_key = "OPENAI_API_KEY"
}

provider "local" {
  source   = "openai_compatible"
  base_url = "http://localhost:11434/v1"   # Ollama, or any Chat Completions endpoint
  price    = { input = 0, output = 0 }     # openai_compatible prices no models
}

provider "fast" {
  source  = "acme/acme"                    # github.com/acme/convoy-provider-acme
  version = "~> 1.4"
  tier    = "priority"                     # an attribute the acme type defines
}
```

## Core attributes

These are the same for every type. Every other attribute in the block is defined by the type.

| Attribute | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `source` | string | yes | | The provider type: a built-in name or an address. |
| `version` | string | no | the newest version the server has | A version constraint. Not allowed with a built-in type. |
| `model` | string | no | | The default model for every agent on this provider, and for the overseer when it names this provider. |
| `price` | object | no | the type's model catalog | USD per million tokens for every model on this provider. |
| `settings` | object | no | `{}` | Defaults for the `settings` of every agent on this provider. |
| `sdk` | string | | | Deprecated name of `source`, accepted for the three built-in types. Set exactly one of the two. |

Every attribute of a provider block is static: it cannot contain references, and an `api_key` cannot contain a function call.

### source

| Form | Example | Meaning |
| --- | --- | --- |
| `<name>` | `openai_compatible` | A built-in type |
| `<namespace>/<name>` | `acme/acme` | The repository `https://github.com/<namespace>/convoy-provider-<name>` |
| `<host>/<namespace>/<name>` | `git.example.com/acme/acme` | The repository `https://<host>/<namespace>/convoy-provider-<name>` |

Addresses are lower-case. You never download a type yourself: convoyd fetches it the first time a swarm names it, and `convoy validate` asks convoyd for its schema. See [Using a provider type](/docs/providers/using/).

### version

A constraint in the syntax OpenTofu uses for provider versions: `"1.4.2"`, `"~> 1.4"` (1.4 or later, below 2.0), `">= 1.2, < 2.0"`. Without one, the newest version convoyd holds is used. A prerelease such as `0.2.0-dev` is selected only by a constraint that names it exactly.

convoyd prefers a version it already holds over a newer one in the repository, so the version a swarm gets changes only when someone runs [`convoy provider pull`](/docs/cli/provider/) or changes `version`. Each run records the version and digest it used.

### model

The default model for every agent on this provider. An agent that sets no [`model`](/docs/dsl/agent/#provider-and-model) of its own runs on this one, and an agent's own `model` wins. The swarm's [`overseer`](/docs/dsl/swarm/#overseer) follows the same rule when it names this provider.

```hcl
provider "llm" {
  source = "claude_agent_sdk"
  model  = "claude-sonnet-5-5"
}

agent "coder" {
  count    = 3
  provider = provider.llm              # claude-sonnet-5-5
  prompt   = file("prompts/coder.md")
}

agent "reviewer" {
  provider = provider.llm
  model    = "claude-opus-5-5"         # its own model wins
  prompt   = file("prompts/reviewer.md")
}
```

With the model in one place, moving a swarm to another provider is a two-line edit, as long as the [tools](#built-in-types) its agents list exist on both types:

```hcl
provider "llm" {
  source = "openai_agents"             # was "claude_agent_sdk"
  model  = "gpt-6.1-sol"               # was "claude-sonnet-5-5"
}
```

The model is resolved when the swarm is loaded. From then on every agent has one concrete model: `convoy status`, the Web UI and the runner never see the difference between a model an agent names and one it takes from its provider. The checks on a model apply to this one as to any other, and are reported once, on this line, however many agents use it: a name outside a closed catalog ([TS019](/docs/dsl/validation/#ts019)), a deprecated model ([TS070](/docs/dsl/validation/#ts070)), and a missing price once `max_cost_usd` is set ([TS060](/docs/dsl/validation/#ts060)). A default that no agent uses is not checked.

An agent with no `model` on a provider with no `model` is [TS004](/docs/dsl/validation/#ts004).

### settings

Defaults for the `settings` of every agent on this provider. An agent's settings resolve key by key: the agent's own [`settings`](/docs/dsl/agent/#settings), then its provider's, then the type's default. A setting none of them sets is not passed to the model at all.

```hcl
provider "openai" {
  source   = "openai_agents"
  settings = { temperature = 0.2, max_tokens = 4000 }
}
```

An unknown key, a value of the wrong type, or one outside the setting's range is [TS018](/docs/dsl/validation/#ts018).

### price

Overrides the type's prices for every model on this provider. The object has these keys, all USD per million tokens:

| Key | Required | Default |
| --- | --- | --- |
| `input` | yes | |
| `output` | yes | |
| `cache_read` | no | the value of `input` |
| `cache_write` | no | the value of `input` |

Values must be numbers of zero or greater. Without `price`, a model's price comes from its type's catalog, keyed by the exact string in an agent's `model`. Use `price` for a model the type does not price: a local model (`price = { input = 0, output = 0 }`), or any model on `openai_compatible`, which prices none. Missing prices are [TS060](/docs/dsl/validation/#ts060) once `max_cost_usd` is set; a malformed `price` is [TS063](/docs/dsl/validation/#ts063).

## Keys are variable names

An attribute whose type is `env_name`, such as every built-in type's `api_key`, holds the **name** of an environment variable, never the key. Keys are not stored in the swarm bundle or the database, and are not read on your machine. convoyd reads the variable from its own environment when it starts a runner and passes the value into that runner's environment, under the name the type gives it.

```hcl
api_key = "ANTHROPIC_API_KEY"   # correct: a variable name
```

The value must be a literal string matching `^[A-Z_][A-Z0-9_]*$`. All of these are [TS014](/docs/dsl/validation/#ts014):

```hcl
api_key = env("ANTHROPIC_API_KEY")    # a function call
api_key = "sk-ant-api03-..."          # looks like a key, not a name
api_key = "anthropic_key"             # lowercase
```

This is deliberate. `env()` values travel in the bundle and are stored with the run. An `api_key` that could call `env()` would put a secret there. Use `api_key` when you want two providers of the same type with different keys, or when the variable has another name.

## Built-in types

The three built-in types ship with Convoy and run in its own runner. The [language reference](/docs/dsl/reference/#provider-types) lists them in full, generated from their manifests.

| `source` | Drives | Attributes | Settings | Built-in tools |
| --- | --- | --- | --- | --- |
| `claude_agent_sdk` | Claude Agent SDK | `api_key` (default `ANTHROPIC_API_KEY`) | `effort` (`low` to `max`), `max_thinking_tokens` | `web_search`, `bash`, `read_file`, `write_file`, `edit_file` |
| `openai_agents` | OpenAI Agents SDK | `api_key` (default `OPENAI_API_KEY`) | `temperature` (0 to 2), `max_tokens` | `web_search`, `bash`, `read_file`, `write_file`, `edit_file`, `code_interpreter`, `file_search` |
| `openai_compatible` | Any Chat Completions endpoint | `api_key` (default `OPENAI_API_KEY`), `base_url` (required), `headers` | `temperature`, `max_tokens` | `bash`, `read_file`, `write_file`, `edit_file` |

All three types offer `bash`, `read_file`, `write_file` and `edit_file` under the same names: the Claude Agent SDK's own tools on `claude_agent_sdk`, and [the runner's](/docs/runtime/runner/#local-tools-on-the-openai-types) on the two OpenAI types. The other OpenAI tools are hosted on OpenAI's platform, so `openai_compatible` does not have them. An `openai_compatible` endpoint must support streaming and function calling, because both the local tools and the [swarm tools](/docs/runtime/swarm-tools/) (the board, `finish`, and so on) reach the model as function tools. `headers` is a map of strings sent with every request:

```hcl
provider "gateway" {
  source   = "openai_compatible"
  base_url = "https://gateway.example.com/v1"
  headers  = { "X-Team" = "research" }
  price    = { input = 1, output = 4 }
}
```

Claude models and the OpenAI models are priced by their types; other model names are accepted and passed through unchanged.

## What validate checks

| Code | Severity | Rule |
| --- | --- | --- |
| [TS003](/docs/dsl/validation/#ts003) | error | An attribute has the wrong type |
| [TS011](/docs/dsl/validation/#ts011) | error | `source` is not a built-in type or an address; `version` is invalid or set on a built-in type; both or neither of `source` and `sdk` |
| [TS012](/docs/dsl/validation/#ts012) | error | The block does not match its type: a required attribute is missing, one it does not define is set, or a value fails its checks |
| [TS014](/docs/dsl/validation/#ts014) | error | An `env_name` attribute, such as `api_key`, is not a literal environment variable name |
| [TS016](/docs/dsl/validation/#ts016) | error | The type could not be resolved |
| [TS017](/docs/dsl/validation/#ts017) | warning | The type was not checked, because no server could be reached |
| [TS018](/docs/dsl/validation/#ts018) | error | `settings` does not match the type's settings |
| [TS060](/docs/dsl/validation/#ts060) | error | `max_cost_usd` is set and a model on this provider has no price |
| [TS063](/docs/dsl/validation/#ts063) | error | `price` is malformed |
| [TS070](/docs/dsl/validation/#ts070) | warning | A deprecated attribute or setting of the type is used |

An agent that names a provider that does not exist is [TS010](/docs/dsl/validation/#ts010), reported on the agent. On the agent too: no `model` on the agent or its provider is [TS004](/docs/dsl/validation/#ts004), and a `tools` entry the type does not offer is [TS013](/docs/dsl/validation/#ts013). A model outside a closed catalog is [TS019](/docs/dsl/validation/#ts019) and a deprecated model is [TS070](/docs/dsl/validation/#ts070), reported where the model is written: on the agent, or on the provider's `model` when agents take it from there.
