---
docId: doc_6294db0e67b8434b83aae2011c97f812
title: 'AI providers'
description: "Use your OpenAI, Google, Anthropic, or xAI account for agents."
---

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

# AI providers

Agents use Platica's AI account by default. Connect your own **OpenAI**, **Google**, **Anthropic**, or **xAI** key to bill that provider's models to your account. This also enables models that require your own key.

## Quick 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": "sk-...", "fallback": "platform"}'
```

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

```ts
// Connecting also tests the key against the provider's models (up to 200 s)
const openai = await platic.aiProviders.connect('openai', {
  value: process.env.OPENAI_API_KEY!,
  fallback: 'platform'
});

if (openai.status !== 'connected') {
  console.log(openai.health, openai.lastError);
}
```

</Ways.Way>
</Ways>

## What you need to know

- **Protected key:** it is stored encrypted as a [secret](/api-reference/secrets). Responses include only `status`, `health`, `fallback`, `secretName`, and `models`.
- **Key test:** connecting or verifying generates a short response per model. It uses a few tokens and may take up to 200 s. Each provider allows 10 tests/hour. A failed test returns `200` with `status: "invalid"` and the reason in `lastError`.
- **Agent fallback models (`fallbackModels`):** adding a new fallback to an agent requires at least one own key that is `connected` (otherwise `422 MODEL_FALLBACKS_REQUIRE_OWN_KEY`). With Platica's account it is not needed.
- **Permissions:** with OAuth it requires **Integrations**, **Settings -> Models (BYOK)**, and secrets permissions (`403 MODELS_ACCESS_DENIED` or `403 FORBIDDEN` if missing). With an API key you have full access.

## States

- **`status`:** `not_connected` (uses Platica's account), `verifying`, `connected` (active), `invalid` (failed; see `lastError`), `disabled`.
- **`health`:** `ok`, `key_rejected`, `no_credit` (if it ran out of balance while in use, it retries every 10 min and recovers on its own when you top up), and `no_model_access`. Changes trigger the [`model_provider.status.updated`](/api-reference/webhooks/payloads#ai-providers) webhook.
- **Per model (`models[].status`):** `available`, `unavailable` (`code`: `AUTH_INVALID`, `AUTH_OR_PERMISSION`, `MODEL_OR_DEPLOYMENT_NOT_FOUND`, `NO_CREDIT`, `QUOTA_OR_RATE_LIMIT`, `TIMEOUT`), or `unverified`.

## The fallback

`fallback` defines what your agents do if your own key fails:

- **`platform`** (default): they answer using Platica's account (it charges AI; `ownKeyOnly` models do not answer).
- **`none`:** they stop answering with that provider's models.

## Endpoints

| Method | Endpoint | What it does |
|--------|----------|--------------|
| `GET` | [`/v1/ai-providers`](/api-reference/ai-providers/list) | List the 4 providers, their state and models |
| `PUT` | [`/v1/ai-providers/{provider}`](/api-reference/ai-providers/connect-key) | Connect or replace the key and test it |
| `POST` | [`/v1/ai-providers/{provider}/verify`](/api-reference/ai-providers/test-key) | Test the stored key again |
| `PATCH` | [`/v1/ai-providers/{provider}`](/api-reference/ai-providers/set-fallback) | Change `fallback` (`platform` or `none`) |
| `DELETE` | [`/v1/ai-providers/{provider}`](/api-reference/ai-providers/disconnect-key) | Disconnect the key |

<span id="common-errors"></span>

Errors (`INVALID_PROVIDER`, `VERIFICATION_RATE_LIMITED`, `VERIFICATION_FAILED`, `MODELS_ACCESS_DENIED`) are in [Errors](/api-reference/errors#ai-providers) and AI tools in [AI providers MCP](/mcp/tools#ai-providers).
