Create a Kafka topic

Create a topic. We add the topic to the brokers in the background, and it's ready a few moments after the response. Kafka Streams can't create its own topics, so create them here first.

POST https://{availability_zone}.betterstackcloud.com/v1/kafka/{kafka_id}/topics
kafka_id string required

The ID of the kafka the Kafka topic belongs to.

Authorization string required

Bearer $TOKEN

Content-Type string

application/json

name string required

The topic's name, unique in the cluster, 1–249 letters, digits, dots, hyphens and underscores. Can't be . or .. or start with __.

partitions integer default: 3

The number of partitions, at least 1. Defaults to 3. All topics together must fit within the cluster type's max_partitions.

retention_bytes integer default: 1073741824

The most data to keep in each partition, in bytes, at least 1048576. Defaults to 1073741824, 1 GiB. All topics together, plus one segment for each partition, must fit in the cluster's storage budget.

retention_ms integer default: 604800000

How long to keep messages, in milliseconds, at least 60000. Defaults to 604800000, 7 days. Send -1 to keep them with no time limit.

cleanup_policy string default: delete

How Kafka removes old messages. Defaults to delete.
Valid values:
delete: Deletes messages older than the retention time or past the retention size.
compact: Keeps only the latest message for each key.
compact_delete: Keeps only the latest message for each key, and also deletes messages past retention. Kafka calls it compact,delete.

max_message_bytes integer default: 1048576

The largest message the topic accepts, in bytes, from 1024 to 8388608. Defaults to 1048576, 1 MiB.

202 Accepted
{
  "id": "example",
  "name": "Example Kafka topic",
  "partitions": 1,
  "replication_factor": 1,
  "retention_bytes": 1,
  "retention_ms": 1,
  "cleanup_policy": "delete",
  "max_message_bytes": 1,
  "budget_bytes": 1,
  "created_at": "2026-07-01T12:00:00.000Z",
  "updated_at": "2026-07-01T12:00:00.000Z"
}

Returns the newly created Kafka topic.

id string

The topic's ID, a UUID. Get, update and delete a topic by this ID, never by its name.

name string

The topic's name, unique in the cluster, 1–249 letters, digits, dots, hyphens and underscores. Can't be . or .. or start with __. Can't be changed after the topic is created.

partitions integer

The number of partitions, at least 1. All topics together must fit within the cluster type's max_partitions.

replication_factor integer

The number of copies of each partition, the same as the cluster's number of brokers.

retention_bytes integer

The most data to keep in each partition, in bytes, at least 1048576.

retention_ms integer

How long to keep messages, in milliseconds, at least 60000. -1 keeps them with no time limit, and retention_bytes still limits their size.

cleanup_policy string

How Kafka removes old messages.
Valid values:
delete: Deletes messages older than the retention time or past the retention size.
compact: Keeps only the latest message for each key.
compact_delete: Keeps only the latest message for each key, and also deletes messages past retention. Kafka calls it compact,delete.

max_message_bytes integer

The largest message the topic accepts, in bytes, from 1024 to 8388608.

budget_bytes integer

The most disk space the topic can use on each broker, in bytes. The budget is partitions times retention_bytes, plus one segment for each partition.

created_at datetime or null

When the topic was created. In ISO 8601 format, such as 2026-07-01T12:00:00Z.

updated_at datetime or null

When the topic was last updated. In ISO 8601 format, such as 2026-07-01T12:00:00Z.