# dokploy_ai (Resource)

An AI provider configuration (Settings > AI): an OpenAI-compatible endpoint that Dokploy's AI features call, for example to suggest a compose file or to analyze a deployment log.

~> **Dokploy stores and returns `api_key` in cleartext.** The attribute is sensitive, so Terraform does not print it, but anyone with API access to the server can read it. The `api_key_wo` companion keeps it out of the Terraform state.

~> Dokploy does not test the endpoint on create or update. A wrong URL, key, or model applies successfully and fails on the first AI request.

## Example Usage

```terraform
# An OpenAI-compatible endpoint for Dokploy's AI features (Settings > AI).
resource "dokploy_ai" "openai" {
  name    = "openai"
  api_url = "https://api.openai.com/v1"
  model   = "gpt-4o-mini"

  # Write-only: Terraform 1.11 or later. Change the version to send a new key.
  api_key_wo         = var.openai_api_key
  api_key_wo_version = 1
}

# A self-hosted model, kept but switched off.
resource "dokploy_ai" "local" {
  name       = "ollama"
  api_url    = "http://ollama.internal:11434/v1"
  model      = "llama3"
  api_key    = "ollama"
  is_enabled = false
}
```

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

### Required

- `api_url` (String) Base URL of the OpenAI-compatible API, for example `https://api.openai.com/v1`.
- `model` (String) Model name that Dokploy sends in each request, for example `gpt-4o-mini`.
- `name` (String) Display name. Dokploy does not enforce a unique name.

### Optional

> **NOTE**: [Write-only arguments](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments) are supported in Terraform 1.11 and later.

- `api_key` (String, Sensitive) API key for the provider. Set this attribute or `api_key_wo`.
- `api_key_wo` (String, Sensitive, [Write-only](https://developer.hashicorp.com/terraform/language/resources/ephemeral#write-only-arguments)) Write-only form of `api_key`. Terraform keeps it out of the plan and the state. It needs Terraform 1.11 or later. Set exactly one of `api_key` and `api_key_wo`. A new value reaches the server only when `api_key_wo_version` changes.
- `api_key_wo_version` (Number) Version of `api_key_wo`. Change it to send the current `api_key_wo` value to the server. It needs `api_key_wo`.
- `is_enabled` (Boolean) Whether Dokploy uses this configuration. Defaults to `true`.
- `verify_connection` (Boolean) Test the connection with `ai.testConnection` before the provider creates or updates the record. If the test fails, the apply fails with the server message, and the provider writes nothing. The default is no check: `null` and `false` both skip the test. Dokploy stores no value for this attribute, so `terraform import` leaves it `null`. The test sends a request to the endpoint with the key and the model, and it retries three times, so a failed test can take several seconds.

### Read-Only

- `created_at` (String) Creation timestamp from the server.
- `id` (String) AI configuration id.
- `organization_id` (String) Id of the organization that owns the configuration.

## Import

Import is supported using the following syntax:

In Terraform v1.5.0 and later, the [`import` block](https://developer.hashicorp.com/terraform/language/import) can be used with the `id` attribute, for example:

```terraform
import {
  to = dokploy_ai.openai
  id = "uNiDiVmkdS0McHxXPUjCt"
}
```

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

```shell
terraform import dokploy_ai.openai uNiDiVmkdS0McHxXPUjCt
```