> ## Documentation Index
> Fetch the complete documentation index at: https://upstash-vector.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Producer API

Producer API is used to send one or more messages to the same or multiple Kafka
topics.

There are three variants of the Producer API:

1. `GET /produce/$TOPIC/$MESSAGE?key=$KEY`:

   Sends a single message (`$MESSAGE`) to a topic (`$TOPIC`) using HTTP GET.
   Optionally message key can be appended with a query parameter`?key=$KEY`.

   Without message key:

   ```shell
   curl https://tops-stingray-7863-eu1-rest-kafka.upstash.io/produce/greetings/hello_kafka -u myuser:mypass
   ```

   With a message key:

   ```shell
   curl https://tops-stingray-7863-eu1-rest-kafka.upstash.io/produce/cities/Istanbul?key=city -u myuser:mypass
   ```

   **Response:**

   A single metadata response is returned as JSON. Its structure is:

   ```typescript
   Metadata{
       topic: String,
       partition: Int,
       offset: Long,
       timestamp: Long
   }
   ```

2. `[GET | POST] /produce/$TOPIC`:

   Produces one or more messages to a single topic (`$TOPIC`). Messages are sent
   using request body as JSON. Structure of the message JSON is:

   ```typescript
   Header {key: String, value: String}

   Message{
       partition?: Int,
       timestamp?: Long,
       key?: String,
       value: String,
       headers?: Array<Header>
   }
   ```

   Only `value` field is required. `partition`, `timestamp`, `key` and `headers`
   fields are optional. When left blank, `partition` and `timestamp` fields will
   be assigned by Kafka brokers. It's valid to send a single message or array of
   messages as JSON.

   * Single message with only value:

   ```shell
   curl https://tops-stingray-7863-eu1-rest-kafka.upstash.io/produce/greetings -u myuser:mypass \
       -d '{"value": "hello_kafka"}'
   ```

   * Single message with multiple attributes:

   ```shell
   curl https://tops-stingray-7863-eu1-rest-kafka.upstash.io/produce/cities -u myuser:mypass \
       -d '{"partition": 1, "key": "city", "value": "Istanbul", "headers": [{"key": "expire", "value": "1637745834756"}] }'
   ```

   * Multiple messages with only values:

   ```shell
   curl https://tops-stingray-7863-eu1-rest-kafka.upstash.io/produce/greetings -u myuser:mypass \
       -d '[
           {"value": "hello_world"},
           {"value": "hello_upstash"},
           {"value": "hello_kafka"}
       ]'
   ```

   * Multiple messages with attributes:

   ```shell
   curl https://tops-stingray-7863-eu1-rest-kafka.upstash.io/produce/cities -u myuser:mypass \
       -d '[
           {"partition": 1, "timestamp": 1637745834744, "key": "city", "value": "Istanbul"},
           {"partition": 2, "timestamp": 1637745823147, "key": "city", "value": "London"},
           {"partition": 3, "timestamp": 1637455583829, "key": "city", "value": "Tokyo"},
       ]'
   ```

   **Response:**

   A metadata array response is returned as JSON. Its structure is same as
   above. Each metadata in the response array belongs the message with the same
   order in the request.

3. `[GET | POST] /produce`:

   Produces one or more messages to a single or multiple topics. Messages are
   sent using request body as JSON. Structure of the message JSON is the same as
   the above, there's only an additional `topic` field:

   ```typescript
   Message{
       topic: String,
       partition?: Int,
       timestamp?: Long,
       key?: String,
       value: String,
       headers?: Array<Header>
   }
   ```

   Only `topic` and `value` fields are required. `partition`, `timestamp`, `key`
   and `headers` fields are optional. When left blank, `partition` and
   `timestamp` fields will be assigned by Kafka brokers. It's valid to send a
   single message or array of messages as JSON.

   * Single message:

   ```shell
   curl https://tops-stingray-7863-eu1-rest-kafka.upstash.io/produce -u myuser:mypass \
       -d '{"topic": "greetings", "value": "hello_kafka"}'
   ```

   * Multiple messages for a single topic:

   ```shell
   curl https://tops-stingray-7863-eu1-rest-kafka.upstash.io/produce -u myuser:mypass \
       -d '[
           {"topic": "greetings", "value": "hello_world"},
           {"topic": "greetings", "value": "hello_upstash"},
           {"topic": "greetings", "value": "hello_kafka"}
       ]'
   ```

   * Multiple messages to multiple topics:

   ```shell
   curl https://tops-stingray-7863-eu1-rest-kafka.upstash.io/produce -u myuser:mypass \
       -d '[
           {"topic": "greetings", "value": "hello_world"},
           {"topic": "greetings", "value": "hello_upstash"},
           {"topic": "cities", "partition": 1, "value": "Istanbul"},
           {"topic": "cities", "partition": 2, "value": "London"},
           {"topic": "cities", "partition": 3, "value": "Tokyo"},
       ]'
   ```

   **Response:**

   A metadata array response is returned as JSON. Its structure is same as
   above. Each metadata in the response array belongs the message with the same
   order in the request.

<Info>
  Producer API works with `acks=all` [producer
  configuration](https://kafka.apache.org/28/documentation.html#producerconfigs_acks),
  which means the topic partition's leader will wait for the all in-sync
  replicas to acknowledge the produced messages.
</Info>
