---
docId: doc_ba323e94350e4f5ba5601c1dc81873d5
title: Authentication
description: "Create an API key and use it from your server or the TypeScript SDK."
---

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

# Authentication

To call the API, create an API key and send it in the `Authorization` header. With the SDK, pass it when creating the client.

<span id="get-your-api-key"></span>

## 1. Create and save your API key

In the app, open **Settings → API Keys**, enter an **API Key name** and click **Create API Key**. You need access to that section and an owner or administrator role.

Copy the key: **it is shown only once**. Store it in an environment variable or a secrets manager. Name it after the integration so you know which key to replace later.

<Collapsible summary="See where to create the API key">

![API Keys section in the Platica dashboard](/images/screenshots/manuales-piloto/configuracion/pantallas-completas/en/api-keys.webp)

See [API keys](/help/settings/api-keys) to manage keys in the app.

</Collapsible>

<span id="send-the-key"></span>

## 2. Use it in your code

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

Pass the key once when creating the client:

```ts
import { Platic } from "platic-sdk";

const platic = new Platic({ apiKey: process.env.PLATIC_API_KEY! });
```

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

Include `Authorization: Bearer` with the key in each request:

```bash
curl -X GET "https://api.platic.ai/v1/agents" \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json"
```

</Ways.Way>
</Ways>

## Workspaces

An API key you create in the app works only in the **workspace where you created it**, even if your account belongs to others. The API selects it automatically. To use API keys across several workspaces, create one in each. A key issued for several workspaces must name one with `?workspace=` where an endpoint requires it, as explained in **OAuth for MCP and multiple workspaces** below.

Use [List workspaces](/api-reference/workspaces) to find their IDs and [Workspaces](/concepts/workspaces) to understand how your data is organized.

<span id="keep-your-key-safe"></span>

<Note type="warning">

Call the API from your server. Keep the key out of public repositories, browser code and mobile apps. To replace it, create and deploy the new key before revoking the old one in the app. If you think someone obtained your key, contact [help@platic.ai](mailto:help@platic.ai).

</Note>

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

## If you receive an error

A `401 Unauthorized` means the credential is missing, invalid, expired or revoked. Check `Authorization` and the key your server is using.

<Collapsible summary="See a 401 response">

```json
{
  "code": 401,
  "error": "Unauthorized - Invalid or expired API key",
  "details": {
    "code": "UNAUTHENTICATED",
    "message": "Invalid or expired API key"
  }
}
```

</Collapsible>

<Collapsible summary="OAuth for MCP and multiple workspaces">

To connect Claude, ChatGPT, Cursor, VS Code or another client, add `https://api.platic.ai/mcp` and sign in with OAuth. Follow [MCP authentication](/mcp/authentication).

| Credential | Prefix | What it's for |
|------------|--------|---------------|
| **API key** | `pl_key_` | REST integrations, scripts, CI, Postman. Full access to the key's workspace. |
| **OAuth (MCP)** | `pl_at_` | Access token Platica issues when connecting an MCP client. It respects your authorized workspaces, scopes and user role. |

Both credentials use the same header:

```bash
Authorization: Bearer pl_key_xxxxxxxxxxxxx
Authorization: Bearer pl_at_xxxxxxxxxxxxx
```

With OAuth, you can authorize several workspaces. When an operation requires a specific one, send `?workspace=<id>`. If it is missing, you receive `400 INVALID_REQUEST` with the available IDs in `details.available`.

Contact, V1 conversation and message lists, `GET /v1/conversations/{id}` and a contact’s conversations can query authorized workspaces without this parameter. Some message, template and email sends also allow this when the channel identifies the workspace. Getting a contact requires `?workspace=` when you can access several. Every `/v2/conversations` call works in one workspace: an API key that covers several sends `?workspace=`. Each endpoint states its rule.

If an OAuth token (`pl_at_…`) receives a `401`, the `WWW-Authenticate` header tells the client how to authorize again under RFC 9728.

If `platica:write` is missing, you receive `403` with `details.code` set to `INSUFFICIENT_SCOPE` and the `insufficient_scope` notice. The client can request write permission; this is called *step-up*. See [MCP authentication](/mcp/authentication) and [Errors](/api-reference/errors).

</Collapsible>
