# Using a provider type

> Name a third-party provider type in a swarm, see what convoyd resolved, pin and upgrade versions, and set the variables it reads.

This page uses an invented provider, Acme, whose type lives at `github.com/acme/convoy-provider-acme`.

## 1. Look at the type

```console
$ convoy provider pull acme/acme
acme/acme 1.4.2 sha256:9f2c3a71b0d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0 (preset)
reads from convoyd's environment by default: api_key = ACME_API_KEY
runs on the built-in openai_compatible driver with:
  driver_config = {
    base_url = attr.base_url
    api_key  = attr.api_key
    headers  = { "X-Acme-Tier" = attr.tier }
  }
```

`pull` is optional: convoyd fetches a type the first time a swarm names it. Pulling first lets you read what you are about to trust: which variable the type reads, and where a preset sends it. `convoy provider show acme/acme` prints the type's attributes, settings, tools, and models with their prices.

## 2. Name it in the swarm

```hcl title="providers.cvy"
provider "fast" {
  source   = "acme/acme"
  version  = "~> 1.4"            # optional
  tier     = "priority"          # an attribute the acme type defines
  settings = { temperature = 0.2 }
}

agent "researcher" {
  provider = provider.fast
  model    = "acme-large-1"
  prompt   = file("prompts/researcher.md")
}
```

Everything besides `source`, `version`, `model`, `price`, and `settings` is defined by the type, and checked against it.

## 3. Validate

```console
$ convoy validate
validate: ok (1 agents, 0 topics)
```

[`convoy validate`](/docs/cli/validate/) asks convoyd for the type's schema, so it checks `tier` against the values the type allows, `settings` against its settings, the agent's `tools` against its tools, and `model` against its catalog. When convoyd is down, it falls back to the copy it cached last time and says so ([TS017](/docs/dsl/validation/#ts017)).

## 4. Set the key on the server

Keys live in convoyd's environment, never in the swarm. The type reads `ACME_API_KEY` by default; set it where convoyd runs, or point `api_key` at another variable:

```hcl
provider "fast" {
  source  = "acme/acme"
  api_key = "ACME_PROD_KEY"
}
```

A variable that is not set refuses `convoy run` with `missing_env`, naming the variable.

## 5. Run

```console
$ convoy run
swarm "report" run 1 accepted: 2 agents pending
provider fast: acme/acme 1.4.2 sha256:9f2c3a71b0d4…
```

The run records `acme/acme 1.4.2` and its digest. `convoy status report --json` shows the list under `providers`:

```json
"providers": [
  { "name": "fast", "source": "acme/acme", "constraint": "~> 1.4", "version": "1.4.2",
    "digest": "sha256:9f2c3a71b0d4…", "kind": "preset" }
]
```

For a driver plugin, the entry also has `runner_version`, the version of the plugin SDK its check reported.

## Versions

| You want | Do |
| --- | --- |
| The newest version the server holds | Leave out `version` |
| Stay on a major version | `version = "~> 1.4"` |
| One exact version | `version = "1.4.2"` |
| A prerelease, such as a release candidate | Name it exactly: `version = "1.5.0-rc1"` |
| Move the server to a newer version | `convoy provider pull acme/acme@~> 1.4` |
| See what the server holds | `convoy provider list` |
| Remove a version | `convoy provider rm acme/acme@1.4.0` |

A version an active run recorded cannot be removed (`provider_in_use`). A newer version pulled while a run is active affects only later runs.

## When something goes wrong

| You see | It means |
| --- | --- |
| [TS016](/docs/dsl/validation/#ts016) | No version meets the constraint, the repository was not found, its manifest is invalid, or it needs a runner contract this convoyd does not speak. The message has the server's reason |
| [TS012](/docs/dsl/validation/#ts012) | An attribute the type does not define, a missing required one, or a value it rejects |
| `provider_check_failed` on `convoy run` | A driver plugin's command failed its check. The message has the end of its output, often a missing dependency or no network for its first install |
| `provider_digest_mismatch` | The provider moved a tag after convoyd fetched it. The stored version is kept; ask the provider to publish a new version |
| `provider_timeout` | A fetch took longer than `--provider-timeout`. It keeps going; run again shortly |
