> For a complete page index of the Captain API documentation, fetch https://docs.captain.dev/llms.txt?excludeSpec=true

# Set Alias

PUT https://acme.captain.dev/v1/aliases/{alias}
Content-Type: application/json

Create an alias, or point it at another index in one step. Every request through the alias reaches the new index from then on.

Reference: https://docs.captain.dev/reference/product-search/indexes/set-alias

## Authentication

- `Authorization` header (bearer token, required) — A write key, issued by Captain. Server side only. Sent as Authorization: Bearer \<key>.

## Request

### Path parameters

- `alias` (string, required)

### Headers

- `Idempotency-Key` (string, optional) — Replays within 24 hours return the stored response (header Idempotent-Replayed: true). The same key on a different request answers 422. A concurrent duplicate answers 409. Failed requests do not keep the key.

### Body (application/json)

This endpoint expects an object.

- `index` (string, required)

## Response

### 200

set

- `alias` (string, optional)
- `index` (string, optional)
- `previous` (string, optional, nullable)

## Examples

**Request**

```json
{
  "index": "products-v2"
}
```

**Response**

```json
{
  "alias": "products",
  "index": "products-v2",
  "previous": "products-v1"
}
```

**SDK Code**

```python Python REST
import json
import requests
import uuid

BASE_URL = "https://acme.captain.dev"
API_KEY = "your_write_key"
ALIAS = "products"

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json",
    "Idempotency-Key": str(uuid.uuid4()),
}

response = requests.put(
    f"{BASE_URL}/v1/aliases/{ALIAS}",
    headers=headers,
    json={
        "index": "products-v2",
    },
    timeout=30.0,
)

print(json.dumps(response.json(), indent=2))
```

```typescript TypeScript REST
const BASE_URL = "https://acme.captain.dev";
const API_KEY = "your_write_key";
const alias = "products";

const response = await fetch(`${BASE_URL}/v1/aliases/${alias}`, {
  method: "PUT",
  headers: {
    Authorization: `Bearer ${API_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": crypto.randomUUID(),
  },
  body: JSON.stringify({
    index: "products-v2",
  }),
});

const result = await response.json();
console.log(JSON.stringify(result, null, 2));
```