---
title: "Rotate a stream key"
canonical_url: "https://tweetstream.io/docs/api/rotate-agent-credential"
last_updated: 2026-11-05
---

# Rotate a stream key

Replace an exposed stream key. The old key, and setup proofs issued for it, stop working at once; the response holds the new key once. A key alone can't rotate: send the setup proof from a recent email code. Not replayable: a retry with the old Standard key gets 401, so verify a new email code to read the key again.

Canonical URL: https://tweetstream.io/docs/api/rotate-agent-credential

## `POST /api/agent/credentials/rotate`

`https://tweetstream.io/api/agent/credentials/rotate`

## Authorization

| Name | Type | Description |
| --- | --- | --- |
| `Authorization` | `string`, required | Bearer authentication with your TweetStream API key: `Bearer <key>`. |

## Headers

| Name | Type | Description |
| --- | --- | --- |
| `X-TweetStream-Setup-Proof` | `string`, required | The setupProof returned by email verification. It lasts 30 minutes; after that, verify a new email code. |

## Body

| Name | Type | Description |
| --- | --- | --- |
| `family` | `enum<string>`, required |  |

### Body example

```json
{
  "family": "BASE"
}
```

## Response fields

| Name | Type | Description |
| --- | --- | --- |
| `apiKey` | `string`, required |  |
| `createdAt` | `string`, required | a string to be decoded into a Date |
| `credentialScope` | `enum<string>`, required |  |
| `family` | `enum<string>`, required |  |

## Responses

| Status | Description | Headers |
| --- | --- | --- |
| `200` | Success |  |
| `400` | Invalid request, wrong code, or the Terms were not accepted |  |
| `401` | Missing or invalid API key, or the setup proof is missing or expired |  |
| `403` | The account is restricted, or the request carried a foreign Origin |  |
| `404` | No such checkout or link, or the account has no entitlement for this product |  |
| `429` | Rate limit or activation budget reached; retry after retryAfterSeconds |  |
| `503` | Temporarily unavailable; retry later |  |

### 200

```json
{
  "apiKey": "<the account's API key, shown once>",
  "createdAt": "2026-10-29T12:02:00.000Z",
  "credentialScope": "STANDARD",
  "family": "BASE"
}
```

### 400

```json
{
  "error": {
    "code": "INVALID_REQUEST",
    "message": "<string>",
    "reason": "not_offered",
    "retryAfterSeconds": 123
  },
  "next": {
    "message": "<string>",
    "action": "call_action",
    "method": "POST",
    "name": "<string>",
    "url": "<string>",
    "who": "agent"
  }
}
```

### 401

```json
{
  "error": {
    "code": "INVALID_REQUEST",
    "message": "<string>",
    "reason": "not_offered",
    "retryAfterSeconds": 123
  },
  "next": {
    "message": "<string>",
    "action": "call_action",
    "method": "POST",
    "name": "<string>",
    "url": "<string>",
    "who": "agent"
  }
}
```

### 403

```json
{
  "error": {
    "code": "INVALID_REQUEST",
    "message": "<string>",
    "reason": "not_offered",
    "retryAfterSeconds": 123
  },
  "next": {
    "message": "<string>",
    "action": "call_action",
    "method": "POST",
    "name": "<string>",
    "url": "<string>",
    "who": "agent"
  }
}
```

### 404

```json
{
  "error": {
    "code": "INVALID_REQUEST",
    "message": "<string>",
    "reason": "not_offered",
    "retryAfterSeconds": 123
  },
  "next": {
    "message": "<string>",
    "action": "call_action",
    "method": "POST",
    "name": "<string>",
    "url": "<string>",
    "who": "agent"
  }
}
```

### 429

```json
{
  "error": {
    "code": "INVALID_REQUEST",
    "message": "<string>",
    "reason": "not_offered",
    "retryAfterSeconds": 123
  },
  "next": {
    "message": "<string>",
    "action": "call_action",
    "method": "POST",
    "name": "<string>",
    "url": "<string>",
    "who": "agent"
  }
}
```

### 503

```json
{
  "error": {
    "code": "INVALID_REQUEST",
    "message": "<string>",
    "reason": "not_offered",
    "retryAfterSeconds": 123
  },
  "next": {
    "message": "<string>",
    "action": "call_action",
    "method": "POST",
    "name": "<string>",
    "url": "<string>",
    "who": "agent"
  }
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url https://tweetstream.io/api/agent/credentials/rotate \
  --header "Authorization: Bearer $TWEETSTREAM_API_KEY" \
  --header "X-TweetStream-Setup-Proof: $TWEETSTREAM_SETUP_PROOF" \
  --header 'Content-Type: application/json' \
  --data '{
  "family": "BASE"
}'
```

### JavaScript

```javascript
const response = await fetch("https://tweetstream.io/api/agent/credentials/rotate", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.TWEETSTREAM_API_KEY}`,
    "X-TweetStream-Setup-Proof": process.env.TWEETSTREAM_SETUP_PROOF,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "family": "BASE"
  }),
});

console.log(response.status, await response.json());
```

### Python

```python
import os
import requests

response = requests.post(
    "https://tweetstream.io/api/agent/credentials/rotate",
    headers={"Authorization": f"Bearer {os.environ['TWEETSTREAM_API_KEY']}", "X-TweetStream-Setup-Proof": os.environ["TWEETSTREAM_SETUP_PROOF"]},
    json={
        "family": "BASE",
    },
)

print(response.status_code, response.json())
```
