---
docId: doc_f9c30f76ec66457ca73716da19046e13
title: Connect an AI provider key
description: "Store and test an AI provider key."
api:
  group: proveedores-de-ia
  auth: bearer
  operations:
    - operationId: connectAiProvider
      method: PUT
      path: '/v1/ai-providers/{provider}'
      postmanName: Connect an AI provider key
---

<script>
  import { Ways, Note } from '$lib/components';
</script>

# Connect an AI provider key

Store and test a provider key in one call. If a key is already connected, replace it.

## Example

<Ways tabs="api,sdk">
<Ways.Way name="api">

```bash
curl -X PUT https://api.platic.ai/v1/ai-providers/openai \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "value": "your-openai-key" }'
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
await platic.aiProviders.connect("openai", { value: "your-openai-key" });
```

</Ways.Way>
</Ways>

## Path parameters

| Parameter | Type | Description | Required |
|-----------|------|-------------|----------|
| `provider` | string | `openai`, `google`, `anthropic`, or `xai` | ✓ |

## Request body

| Field | Type | Description | Required |
|-------|------|-------------|----------|
| `value` | string | The provider's key, up to 4,096 characters | ✓ |
| `fallback` | string | What agents do while the key does not work: `platform` or `none`. Without it, the provider keeps the one it had, or `platform` if it is new. See [the fallback](/api-reference/ai-providers#the-fallback) | — |

```json
{
  "value": "sk-proj-example",
  "fallback": "platform"
}
```

## Response

`200 OK` with the provider after the test, in the shape of [list AI providers](/api-reference/ai-providers/list#the-provider). It never includes the key.

```json
{
  "status": "success",
  "message": "Key connected and verified",
  "data": {
    "provider": "openai",
    "name": "OpenAI",
    "status": "connected",
    "health": "ok",
    "fallback": "platform",
    "lastVerifiedAt": "2026-11-13T16:20:00.000Z",
    "lastError": null,
    "secretName": "OpenAI key",
    "models": [
      { "id": "gpt-6.1-sol", "name": "GPT-6.1 Sol", "status": "available", "code": null, "ownKeyOnly": false },
      { "id": "gpt-6.1-terra", "name": "GPT-6.1 Terra", "status": "available", "code": null, "ownKeyOnly": false },
      { "id": "gpt-6-luna", "name": "GPT-6 Luna", "status": "unavailable", "code": "MODEL_OR_DEPLOYMENT_NOT_FOUND", "ownKeyOnly": false }
    ]
  }
}
```

If the key does not work, the response is also `200`: `status` is `invalid`, `lastError` says why, and `message` is `Key saved, but it does not work: see lastError`.

## Errors

| Status | `details.code` | When it happens |
|--------|----------------|-----------------|
| `400` | `INVALID_PROVIDER` | `{provider}` is not one of the four |
| `400` | `INVALID_REQUEST` | `value` is missing, empty, or over 4,096 characters, `fallback` is neither `platform` nor `none`, or the body has an unknown field. `details.issues` says which, without repeating the key |
| `403` | `FORBIDDEN` | The person behind the token cannot manage and use secrets |
| `429` | `VERIFICATION_RATE_LIMITED` | There were already 10 tests of that provider in the last hour |
| `503` | `VERIFICATION_FAILED` | The key could not be tested with the provider. [Get the provider](/api-reference/ai-providers/list) before retrying |

<Note type="warning">

Do not log or display the key after sending it. If an AI assistant connects it for you, the key goes through that conversation: to avoid it, connect it in Platica, under **Settings → Models (BYOK)**.

</Note>

## Notes

- The test spends a few tokens from your provider account and can take a while: wait for the response for up to 200 seconds.
- The key is stored as a workspace secret named, for example, `OpenAI key`. Replacing it stores the new one, removes the authorization of the previous one, and deletes it from Secrets. If you renamed the previous one or another integration uses it, it stays in [Secrets](/api-reference/secrets/list).
- To test it again without sending it, use [test an AI provider key](/api-reference/ai-providers/test-key).
