Updated on 2025-09-03 GMT+08:00

Creating a Topic for a Kafka Instance

Function

This API is used to create a topic for a Kafka instance.

URI

POST /v2/{project_id}/instances/{instance_id}/topics

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Definition:

Project ID. For details, see Obtaining a Project ID.

Constraints:

N/A

Range:

N/A

Default Value:

N/A

instance_id

Yes

String

Definition:

Instance ID. You can call the API for querying all instances to obtain the instance ID. The instance ID is in the response body.

Constraints:

N/A

Range:

N/A

Default Value:

N/A

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

id

Yes

String

Definition:

Topic name.

Constraints:

A topic name consists of 3 to 200 characters, starts with a letter, and contains only letters, hyphens (-), underscores (_), periods (.), and digits.

Range:

N/A

Default Value:

N/A

replication

No

Integer

Definition:

Number of replicas, which is configured to ensure data reliability.

Constraints:

The number of replicas is related to the number of brokers. If there are three brokers, the maximum number of replicas is 3.

Range:

N/A

Default Value:

N/A

sync_message_flush

No

Boolean

Definition:

Whether to enable synchronous flushing. Synchronous flushing causes performance deterioration.

Constraints:

N/A

Range:

  • true: Yes

  • false: No

Default Value:

false

partition

No

Integer

Definition:

Number of topic partitions, which is used to set the number of the consumption concurrency.

Constraints:

N/A

Range:

1–200

Default Value:

N/A

sync_replication

No

Boolean

Definition:

Whether to enable synchronous replication.

Constraints:

N/A

Range:

  • true: yes The acks parameter on the producer client must be set to –1. Otherwise, this parameter does not take effect.

  • false: no

Default Value:

false

retention_time

No

Integer

Definition:

Message retention period.

Constraints:

N/A

Range:

1–720

Default Value:

72

topic_other_configs

No

Array of topic_other_configs objects

Definition:

Topic configuration

topic_desc

No

String

Definition:

Topic description.

Constraints:

N/A

Range:

0 to 200 characters

Default Value:

N/A

Table 3 topic_other_configs

Parameter

Mandatory

Type

Description

name

No

String

Definition:

Configuration name.

Constraints:

N/A

Range:

N/A

Default Value:

N/A

value

No

String

Definition:

Configuration value.

Constraints:

N/A

Range:

N/A

Default Value:

N/A

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

name

String

Definition:

Topic name.

Range:

N/A

Example Requests

Creating a topic named test01

POST https://{endpoint}/v2/{project_id}/instances/{instance_id}/topics

{
  "id" : "test01",
  "partition" : 3,
  "replication" : 3,
  "retention_time" : 72,
  "sync_message_flush" : false,
  "sync_replication" : "false",
  "topic_other_configs" : [ {
    "name" : "message.timestamp.type",
    "value" : "LogAppendTime"
  }, {
    "name" : "max.message.bytes",
    "value" : 10485760
  } ],
  "topic_desc" : ""
}

Example Responses

Status code: 200

Successful. A topic name is returned.

{
  "name" : "test01"
}

Status Codes

Status Code

Description

200

Successful. A topic name is returned.

Error Codes

See Error Codes.