# AI Providers

## List AI providers [#list-ai-providers]

### Code samples [#code-samples]

```sh
# Example request using curl
curl -X GET http://coder-server:8080/api/v2/ai/providers \
  -H 'Accept: application/json' \
  -H 'Coder-Session-Token: API_KEY'
```

`GET /api/v2/ai/providers`

### Example responses [#example-responses]

> 200 Response

```json
[
  {
    "api_keys": [
      {
        "created_at": "2019-08-24T14:15:22Z",
        "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
        "masked": "string"
      }
    ],
    "base_url": "string",
    "created_at": "2019-08-24T14:15:22Z",
    "display_name": "string",
    "enabled": true,
    "icon": "string",
    "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
    "name": "string",
    "settings": {},
    "status": {
      "warnings": [
        "string"
      ]
    },
    "type": "openai",
    "updated_at": "2019-08-24T14:15:22Z"
  }
]
```

### Responses [#responses]

| Status | Meaning                                                 | Description | Schema                                                                               |
| ------ | ------------------------------------------------------- | ----------- | ------------------------------------------------------------------------------------ |
| 200    | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK          | array of [codersdk.AIProvider](/beta-docs/reference/api/schemas/#codersdkaiprovider) |

<h3 id="list-ai-providers-responseschema">Response Schema</h3>

Status Code **200**

| Name             | Type                                                                                        | Required | Restrictions | Description                                            |
| ---------------- | ------------------------------------------------------------------------------------------- | -------- | ------------ | ------------------------------------------------------ |
| `[array item]`   | array                                                                                       | false    |              |                                                        |
| `» api_keys`     | array                                                                                       | false    |              |                                                        |
| `»» created_at`  | string(date-time)                                                                           | false    |              |                                                        |
| `»» id`          | string(uuid)                                                                                | false    |              |                                                        |
| `»» masked`      | string                                                                                      | false    |              |                                                        |
| `» base_url`     | string                                                                                      | false    |              |                                                        |
| `» created_at`   | string(date-time)                                                                           | false    |              |                                                        |
| `» display_name` | string                                                                                      | false    |              |                                                        |
| `» enabled`      | boolean                                                                                     | false    |              |                                                        |
| `» icon`         | string                                                                                      | false    |              |                                                        |
| `» id`           | string(uuid)                                                                                | false    |              |                                                        |
| `» name`         | string                                                                                      | false    |              |                                                        |
| `» settings`     | [codersdk.AIProviderSettings](/beta-docs/reference/api/schemas/#codersdkaiprovidersettings) | false    |              |                                                        |
| `» status`       | [codersdk.AIProviderStatus](/beta-docs/reference/api/schemas/#codersdkaiproviderstatus)     | false    |              | Status carries runtime routing status; nil when empty. |
| `»» warnings`    | array                                                                                       | false    |              |                                                        |
| `» type`         | [codersdk.AIProviderType](/beta-docs/reference/api/schemas/#codersdkaiprovidertype)         | false    |              |                                                        |
| `» updated_at`   | string(date-time)                                                                           | false    |              |                                                        |

#### Enumerated Values [#enumerated-values]

| Property | Value(s)                                                                                                |
| -------- | ------------------------------------------------------------------------------------------------------- |
| `type`   | `anthropic`, `azure`, `bedrock`, `copilot`, `google`, `openai`, `openai-compat`, `openrouter`, `vercel` |

To perform this operation, you must be authenticated. [Learn more](/beta-docs/reference/api/authentication/).

## Create an AI provider [#create-an-ai-provider]

### Code samples [#code-samples-1]

```sh
# Example request using curl
curl -X POST http://coder-server:8080/api/v2/ai/providers \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'Coder-Session-Token: API_KEY'
```

`POST /api/v2/ai/providers`

> Body parameter

```json
{
  "api_keys": [
    "string"
  ],
  "base_url": "string",
  "display_name": "string",
  "enabled": true,
  "icon": "string",
  "name": "string",
  "settings": {},
  "type": "openai"
}
```

### Parameters [#parameters]

| Name   | In   | Type                                                                                                  | Required | Description                |
| ------ | ---- | ----------------------------------------------------------------------------------------------------- | -------- | -------------------------- |
| `body` | body | [codersdk.CreateAIProviderRequest](/beta-docs/reference/api/schemas/#codersdkcreateaiproviderrequest) | true     | Create AI provider request |

### Example responses [#example-responses-1]

> 201 Response

```json
{
  "api_keys": [
    {
      "created_at": "2019-08-24T14:15:22Z",
      "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
      "masked": "string"
    }
  ],
  "base_url": "string",
  "created_at": "2019-08-24T14:15:22Z",
  "display_name": "string",
  "enabled": true,
  "icon": "string",
  "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
  "name": "string",
  "settings": {},
  "status": {
    "warnings": [
      "string"
    ]
  },
  "type": "openai",
  "updated_at": "2019-08-24T14:15:22Z"
}
```

### Responses [#responses-1]

| Status | Meaning                                                      | Description | Schema                                                                      |
| ------ | ------------------------------------------------------------ | ----------- | --------------------------------------------------------------------------- |
| 201    | [Created](https://tools.ietf.org/html/rfc7231#section-6.3.2) | Created     | [codersdk.AIProvider](/beta-docs/reference/api/schemas/#codersdkaiprovider) |

To perform this operation, you must be authenticated. [Learn more](/beta-docs/reference/api/authentication/).

## Get an AI provider [#get-an-ai-provider]

### Code samples [#code-samples-2]

```sh
# Example request using curl
curl -X GET http://coder-server:8080/api/v2/ai/providers/{idOrName} \
  -H 'Accept: application/json' \
  -H 'Coder-Session-Token: API_KEY'
```

`GET /api/v2/ai/providers/{idOrName}`

### Parameters [#parameters-1]

| Name       | In   | Type   | Required | Description         |
| ---------- | ---- | ------ | -------- | ------------------- |
| `idOrName` | path | string | true     | Provider ID or name |

### Example responses [#example-responses-2]

> 200 Response

```json
{
  "api_keys": [
    {
      "created_at": "2019-08-24T14:15:22Z",
      "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
      "masked": "string"
    }
  ],
  "base_url": "string",
  "created_at": "2019-08-24T14:15:22Z",
  "display_name": "string",
  "enabled": true,
  "icon": "string",
  "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
  "name": "string",
  "settings": {},
  "status": {
    "warnings": [
      "string"
    ]
  },
  "type": "openai",
  "updated_at": "2019-08-24T14:15:22Z"
}
```

### Responses [#responses-2]

| Status | Meaning                                                 | Description | Schema                                                                      |
| ------ | ------------------------------------------------------- | ----------- | --------------------------------------------------------------------------- |
| 200    | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK          | [codersdk.AIProvider](/beta-docs/reference/api/schemas/#codersdkaiprovider) |

To perform this operation, you must be authenticated. [Learn more](/beta-docs/reference/api/authentication/).

## Delete an AI provider [#delete-an-ai-provider]

### Code samples [#code-samples-3]

```sh
# Example request using curl
curl -X DELETE http://coder-server:8080/api/v2/ai/providers/{idOrName} \
  -H 'Coder-Session-Token: API_KEY'
```

`DELETE /api/v2/ai/providers/{idOrName}`

### Parameters [#parameters-2]

| Name       | In   | Type   | Required | Description         |
| ---------- | ---- | ------ | -------- | ------------------- |
| `idOrName` | path | string | true     | Provider ID or name |

### Responses [#responses-3]

| Status | Meaning                                                         | Description | Schema |
| ------ | --------------------------------------------------------------- | ----------- | ------ |
| 204    | [No Content](https://tools.ietf.org/html/rfc7231#section-6.3.5) | No Content  |        |

To perform this operation, you must be authenticated. [Learn more](/beta-docs/reference/api/authentication/).

## Update an AI provider [#update-an-ai-provider]

### Code samples [#code-samples-4]

```sh
# Example request using curl
curl -X PATCH http://coder-server:8080/api/v2/ai/providers/{idOrName} \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'Coder-Session-Token: API_KEY'
```

`PATCH /api/v2/ai/providers/{idOrName}`

> Body parameter

```json
{
  "api_keys": [
    {
      "api_key": "string",
      "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08"
    }
  ],
  "base_url": "string",
  "display_name": "string",
  "enabled": true,
  "icon": "string",
  "settings": {}
}
```

### Parameters [#parameters-3]

| Name       | In   | Type                                                                                                  | Required | Description                |
| ---------- | ---- | ----------------------------------------------------------------------------------------------------- | -------- | -------------------------- |
| `idOrName` | path | string                                                                                                | true     | Provider ID or name        |
| `body`     | body | [codersdk.UpdateAIProviderRequest](/beta-docs/reference/api/schemas/#codersdkupdateaiproviderrequest) | true     | Update AI provider request |

### Example responses [#example-responses-3]

> 200 Response

```json
{
  "api_keys": [
    {
      "created_at": "2019-08-24T14:15:22Z",
      "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
      "masked": "string"
    }
  ],
  "base_url": "string",
  "created_at": "2019-08-24T14:15:22Z",
  "display_name": "string",
  "enabled": true,
  "icon": "string",
  "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
  "name": "string",
  "settings": {},
  "status": {
    "warnings": [
      "string"
    ]
  },
  "type": "openai",
  "updated_at": "2019-08-24T14:15:22Z"
}
```

### Responses [#responses-4]

| Status | Meaning                                                 | Description | Schema                                                                      |
| ------ | ------------------------------------------------------- | ----------- | --------------------------------------------------------------------------- |
| 200    | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK          | [codersdk.AIProvider](/beta-docs/reference/api/schemas/#codersdkaiprovider) |

To perform this operation, you must be authenticated. [Learn more](/beta-docs/reference/api/authentication/).
