# API keys

Source: https://docs.sociaro.com/keys/

An API key authenticates requests and attributes usage to its organisation.

## Create a key

Open **Keys → Create key** in the [console](https://my.sociaro.com). A name is optional. For example, a key named `production` can appear as `Acme 3 · production`. Use this display name in support requests.

Copy the secret when it appears and store it in a server-side secret manager. The console displays it once. If you lose it, create a replacement and revoke the old key.

## Expiration

Choose **Never** (default), **30 days**, **90 days** or **1 year** at creation. The expiry cannot be changed. The Keys tab shows the expiration time in UTC. Replace the key before that time to avoid authentication failures.

## Authentication

Send the key in the `Authorization` header with the `Bearer` scheme:

cURL

```bash
curl https://api.sociaro.com/v1/models \
  -H "Authorization: Bearer $SOCIARO_API_KEY"
```

Python

```python
# Requires Python 3 and requests (pip install requests).
import os
import requests

response = requests.get(
    'https://api.sociaro.com/v1/models',
    headers={
        'Authorization': 'Bearer ' + os.environ['SOCIARO_API_KEY'],
    },
    timeout=120,
)
response.raise_for_status()
print(response.text)
```

JavaScript

```javascript
// Run as an .mjs file with Node.js 22 or later.

const response = await fetch("https://api.sociaro.com/v1/models", {
  headers: {
    "Authorization": "Bearer " + process.env.SOCIARO_API_KEY,
  },
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
console.log(await response.text());
```

Use `GET /v1/models` for v1 discovery and `GET /v2/models` for [Jobs API models](https://docs.sociaro.com/jobs/models/index.md).

## Revoke a key

Select **Revoke** on the Keys tab to disable the key immediately. Select **Delete** afterwards to remove it from the list. Existing usage and charges remain visible in **Spend** and **Logs**, marked `(deleted)`.

If a key is exposed, revoke it and replace it wherever it was configured.

## Organisation scope

Every key in an organisation uses its shared balance. Use `GET /v1/balance` to read the remaining amount. Some features require activation for the organisation. See [balance and billing](https://docs.sociaro.com/billing/index.md).
