> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hookstream.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Create topic

Create a new pub/sub topic.

` POST /topics `

Create topic

Create a new pub/sub topic.

## Servers

- ` https://hookstream.io/v1 ` — Production

## Authentication

The operation accepts these alternatives. Schemes within one alternative are required together.

### Alternative 1

- ` apiKey `: ` apiKey `

  - Credential: ` X-API-Key ` in ` header `

  - API key (format: hs_live_<64hex> or hs_test_<64hex>)

### Alternative 2

- ` cookieAuth `: ` apiKey `

  - Credential: ` better-auth.session_token ` in ` cookie `

  - Session cookie (browser auth)

## Request body (required)

Content type: ` application/json `

Request body

- ` value `: type ` object `

  - Required fields: ` name `, ` slug `

  - ` org_id `: type ` string ` — Organization ID (defaults to auth context)

  - ` env_id `: type ` string ` — Environment ID (defaults to auth context)

  - ` name `: type ` string ` — Topic name

    - example: ` "order.events" `

    - minLength: ` 1 `

  - ` slug `: type ` string ` — URL-safe slug for publishing

    - example: ` "order-events" `

    - minLength: ` 1 `

  - ` description `: type ` string ` — Optional description

  - ` schema `: type ` object ` — Optional JSON Schema for validation

## Responses

### ` 201 ` — Topic created

Content type: ` application/json `

- ` value `: type ` object `

  - Required fields: ` topic `

  - ` topic `: type ` object `; nullable

    - Required fields: ` id `, ` org_id `, ` env_id `, ` name `, ` slug `, ` description `, ` schema `, ` status `, ` created_at `, ` updated_at `

    - ` id `: type ` string `

    - ` org_id `: type ` string `

    - ` env_id `: type ` string `

    - ` name `: type ` string `

    - ` slug `: type ` string `

    - ` description `: type ` string `; nullable

    - ` schema `: type ` string `; nullable

    - ` status `: type ` string `

    - ` created_at `: type ` string `

    - ` updated_at `: type ` string `

### ` 400 ` — Bad request

Content type: ` application/json `

- ` value `: type ` object `

  - Required fields: ` error `

  - ` error `: type ` string ` — Error message

### ` 401 ` — Unauthorized

Content type: ` application/json `

- ` value `: type ` object `

  - Required fields: ` error `

  - ` error `: type ` string ` — Error message

### ` 409 ` — Slug already exists

Content type: ` application/json `

- ` value `: type ` object `

  - Required fields: ` error `

  - ` error `: type ` string ` — Error message

## Request examples

### cURL

```curl
curl -X POST 'https://hookstream.io/v1/topics' \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "org_id": "string",
  "env_id": "string",
  "name": "order.events",
  "slug": "order-events",
  "description": "string",
  "schema": {}
}'
```

### JavaScript

```javascript
const response = await fetch('https://hookstream.io/v1/topics', {
  method: 'POST',
  headers: {
      "Authorization": "Bearer YOUR_API_TOKEN",
      "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "org_id": "string",
    "env_id": "string",
    "name": "order.events",
    "slug": "order-events",
    "description": "string",
    "schema": {}
  })
});

const data = await response.json();
console.log(data);
```

### Python

```python
import requests

headers = {
    'Authorization': 'Bearer YOUR_API_TOKEN'
}

response = requests.post('https://hookstream.io/v1/topics', headers=headers, json={
  "org_id": "string",
  "env_id": "string",
  "name": "order.events",
  "slug": "order-events",
  "description": "string",
  "schema": {}
})
print(response.json())
```

### Go

```go
package main

import (
	"fmt"
	"io"
	"net/http"
	"strings"
)

func main() {
	body := strings.NewReader(`{
  "org_id": "string",
  "env_id": "string",
  "name": "order.events",
  "slug": "order-events",
  "description": "string",
  "schema": {}
}`)
	req, _ := http.NewRequest("POST", "https://hookstream.io/v1/topics", body)
	req.Header.Set("Authorization", "Bearer YOUR_API_TOKEN")
	req.Header.Set("Content-Type", "application/json")

	resp, _ := http.DefaultClient.Do(req)
	defer resp.Body.Close()
	result, _ := io.ReadAll(resp.Body)
	fmt.Println(string(result))
}
```