Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions docs/resources/agents_model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "coderd_agents_model Resource - terraform-provider-coderd"
subcategory: ""
description: |-
~> This resource is experimental. Changes are to be expected, and we recommend using it with caution in production environments.
Configures an admin-managed chat model for Coder Agents, binding a model identifier to a configured AI provider (see coderd_ai_provider) along with context, compression, and optional JSON tuning settings.
---

# coderd_agents_model (Resource)

~> This resource is experimental. Changes are to be expected, and we recommend using it with caution in production environments.

Configures an admin-managed chat model for Coder Agents, binding a model identifier to a configured AI provider (see `coderd_ai_provider`) along with context, compression, and optional JSON tuning settings.

## Example Usage

```terraform
variable "anthropic_api_key" {
type = string
sensitive = true
}

resource "coderd_ai_provider" "anthropic" {
type = "anthropic"
name = "anthropic"
base_url = "https://api.anthropic.com"

api_key_wo = var.anthropic_api_key
api_key_wo_version = 1
}

resource "coderd_agents_model" "sonnet" {
ai_provider_id = coderd_ai_provider.anthropic.id
model = "claude-3-5-sonnet-20241022"
display_name = "Claude 3.5 Sonnet"
enabled = true
context_limit = 200000

model_config = jsonencode({
max_output_tokens = 8192
temperature = 0.7
cost = {
input_price_per_million_tokens = "3"
output_price_per_million_tokens = "15"
}
provider_options = {
anthropic = {
effort = "high"
thinking = { budget_tokens = 4096 }
}
}
})
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `ai_provider_id` (String) AI provider ID that backs this model. Usually this is `coderd_ai_provider.<name>.id`. Updating it re-derives the read-only `provider_type` from the referenced provider.
- `context_limit` (Number) Maximum context window for this model. Must be greater than zero.
- `model` (String) Model identifier to use with the referenced provider.

### Optional

- `compression_threshold` (Number) Percentage of the context window at which Coder should compact chat context. Defaults to 70 and must be between 0 and 100.
- `display_name` (String) Display name shown in Coder.
- `enabled` (Boolean) Whether this model configuration is enabled. Defaults to true.
- `model_config` (String) Optional JSON blob of per-call tuning for the model, such as `max_output_tokens`, `temperature`, `top_p`, `cost`, and `provider_options`. See the field reference (including per-provider `provider_options`) at https://pkg.go.dev/github.com/coder/coder/v2/codersdk#ChatModelCallConfig.

### Read-Only

- `created_at` (Number) Creation timestamp as Unix seconds.
- `id` (String) Agents model configuration ID.
- `provider_type` (String) Provider type derived by Coder from `ai_provider_id`, for example `openai`, `anthropic`, or `bedrock`.
- `updated_at` (Number) Last update timestamp as Unix seconds.

## Import

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
# The ID supplied must be the Agents model configuration UUID returned by Coder.
$ terraform import coderd_agents_model.sonnet <model-config-id>
```
Alternatively, in Terraform v1.5.0 and later, an [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used:

```terraform
import {
to = coderd_agents_model.sonnet
id = "<model-config-id>"
}
```
10 changes: 10 additions & 0 deletions examples/resources/coderd_agents_model/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# The ID supplied must be the Agents model configuration UUID returned by Coder.
$ terraform import coderd_agents_model.sonnet <model-config-id>
```
Alternatively, in Terraform v1.5.0 and later, an [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used:

```terraform
import {
to = coderd_agents_model.sonnet
id = "<model-config-id>"
}
36 changes: 36 additions & 0 deletions examples/resources/coderd_agents_model/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
variable "anthropic_api_key" {
type = string
sensitive = true
}

resource "coderd_ai_provider" "anthropic" {
type = "anthropic"
name = "anthropic"
base_url = "https://api.anthropic.com"

api_key_wo = var.anthropic_api_key
api_key_wo_version = 1
}

resource "coderd_agents_model" "sonnet" {
ai_provider_id = coderd_ai_provider.anthropic.id
model = "claude-3-5-sonnet-20241022"
display_name = "Claude 3.5 Sonnet"
enabled = true
context_limit = 200000

model_config = jsonencode({
max_output_tokens = 8192
temperature = 0.7
cost = {
input_price_per_million_tokens = "3"
output_price_per_million_tokens = "15"
}
provider_options = {
anthropic = {
effort = "high"
thinking = { budget_tokens = 4096 }
}
}
})
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ require (
github.com/coder/websocket v1.8.15
github.com/docker/docker v28.5.2+incompatible
github.com/docker/go-connections v0.7.0
github.com/google/go-cmp v0.7.0
github.com/google/uuid v1.6.0
github.com/hashicorp/terraform-plugin-docs v0.25.0
github.com/hashicorp/terraform-plugin-framework v1.19.0
github.com/hashicorp/terraform-plugin-framework-jsontypes v0.2.0
github.com/hashicorp/terraform-plugin-framework-validators v0.19.0
github.com/hashicorp/terraform-plugin-go v0.31.0
github.com/hashicorp/terraform-plugin-log v0.10.0
Expand Down Expand Up @@ -85,7 +87,6 @@ require (
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/pprof v0.0.0-20250607225305-033d6d78b36a // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ github.com/hashicorp/terraform-plugin-docs v0.25.0 h1:qHs1V257NxVe8tv6HS4UQfNqja
github.com/hashicorp/terraform-plugin-docs v0.25.0/go.mod h1:MQggCmY8zgP7R7E/cC0b0cmTvA9hSj3ZKyrrsDjRbLo=
github.com/hashicorp/terraform-plugin-framework v1.19.0 h1:q0bwyhxAOR3vfdgbk9iplv3MlTv/dhBHTXjQOtQDoBA=
github.com/hashicorp/terraform-plugin-framework v1.19.0/go.mod h1:YRXOBu0jvs7xp4AThBbX4mAzYaMJ1JgtFH//oGKxwLc=
github.com/hashicorp/terraform-plugin-framework-jsontypes v0.2.0 h1:SJXL5FfJJm17554Kpt9jFXngdM6fXbnUnZ6iT2IeiYA=
github.com/hashicorp/terraform-plugin-framework-jsontypes v0.2.0/go.mod h1:p0phD0IYhsu9bR4+6OetVvvH59I6LwjXGnTVEr8ox6E=
github.com/hashicorp/terraform-plugin-framework-validators v0.19.0 h1:Zz3iGgzxe/1XBkooZCewS0nJAaCFPFPHdNJd8FgE4Ow=
github.com/hashicorp/terraform-plugin-framework-validators v0.19.0/go.mod h1:GBKTNGbGVJohU03dZ7U8wHqc2zYnMUawgCN+gC0itLc=
github.com/hashicorp/terraform-plugin-go v0.31.0 h1:0Fz2r9DQ+kNNl6bx8HRxFd1TfMKUvnrOtvJPmp3Z0q8=
Expand Down
119 changes: 119 additions & 0 deletions integration/agents-model-test/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
terraform {
required_providers {
coderd = {
source = "coder/coderd"
version = ">=0.0.0"
}
}
}

resource "coderd_ai_provider" "anthropic" {
type = "anthropic"
name = "agents-anthropic"
display_name = "Anthropic"
base_url = "https://api.anthropic.com/"

api_key_wo = "sk-ant-api03-integration-test"
api_key_wo_version = 1
}

resource "coderd_ai_provider" "openai" {
type = "openai"
name = "agents-openai"
display_name = "OpenAI"
base_url = "https://api.openai.com/v1"

api_key_wo = "sk-integration-test-openai"
api_key_wo_version = 1
}

resource "coderd_agents_model" "claude_opus" {
ai_provider_id = coderd_ai_provider.anthropic.id
model = "claude-opus-4-8"
display_name = "Claude Opus 4.8"
context_limit = 1000000
compression_threshold = 42

model_config = jsonencode({
max_output_tokens = 128000
cost = {
input_price_per_million_tokens = "5"
output_price_per_million_tokens = "25"
cache_read_price_per_million_tokens = "0.5"
cache_write_price_per_million_tokens = "6.25"
}
provider_options = {
anthropic = {
send_reasoning = true
effort = "high"
}
}
})
}

resource "coderd_agents_model" "claude_sonnet" {
ai_provider_id = coderd_ai_provider.anthropic.id
model = "claude-sonnet-4-6"
display_name = "Claude Sonnet 4.6"
context_limit = 200000
compression_threshold = 70

model_config = jsonencode({
cost = {
input_price_per_million_tokens = "3"
output_price_per_million_tokens = "15"
}
provider_options = {
anthropic = {
send_reasoning = true
effort = "max"
web_search_enabled = true
thinking = {
budget_tokens = 16000
}
}
}
})
}

resource "coderd_agents_model" "gpt_xhigh" {
ai_provider_id = coderd_ai_provider.openai.id
model = "gpt-5.5"
display_name = "GPT-5.5"
context_limit = 272000
compression_threshold = 70

model_config = jsonencode({
cost = {
input_price_per_million_tokens = "2.5"
output_price_per_million_tokens = "15"
cache_read_price_per_million_tokens = "0.25"
}
provider_options = {
openai = {
parallel_tool_calls = false
reasoning_effort = "xhigh"
reasoning_summary = "detailed"
text_verbosity = "high"
web_search_enabled = true
search_context_size = "medium"
}
}
})
}

resource "coderd_agents_model" "gpt_mini" {
ai_provider_id = coderd_ai_provider.openai.id
model = "gpt-5.4-mini"
display_name = "GPT-5.4 Mini"
context_limit = 400000
compression_threshold = 70

model_config = jsonencode({
provider_options = {
openai = {
reasoning_effort = "medium"
}
}
})
}
Loading