# Publish pubsub

URL: https://docs.hanzo.ai/docs/openapi/pubsub/post-pubsub-publish

> Puts one message on the org's bus.

`POST /v1/pubsub/publish`

> [Pubsub →](https://docs.hanzo.ai/docs/openapi/pubsub) · [All API references →](https://docs.hanzo.ai/docs/openapi) · [Get started →](https://docs.hanzo.ai/docs/guides)

|               |                                          |
| ------------- | ---------------------------------------- |
| **Address**   | `https://api.hanzo.ai/v1/pubsub/publish` |
| **Method**    | `POST`                                   |
| **Operation** | `post_pubsub_publish`                    |
| **Auth**      | `Authorization: Bearer $HANZO_API_KEY`   |

Puts one message on the org's bus. When a stream captures the subject
the write is DURABLE — the receipt names the stream and sequence only after
JetStream has it on storage, and a repeated Nats-Msg-Id header within the
dedup window answers duplicate instead of storing twice. When nothing
captures it, the message goes out core NATS: delivered to current
subscribers, receipt {ok}, nothing retained.

## Request

4 fields, body `application/json` (required).

| Field       | In   | Type   | Required | Description                                                                             |
| ----------- | ---- | ------ | -------- | --------------------------------------------------------------------------------------- |
| `data`      | body | string | —        | Data is the payload, carried verbatim as UTF-8 text (typically JSON).                   |
| `headers`   | body | object | —        | Headers are optional message headers, one value per name.                               |
| `headers.*` | body | string | —        |                                                                                         |
| `subject`   | body | string | —        | Subject is the subject to publish to, in the org's own namespace — e.g. orders.created. |

## Response

| Status    | Body            | Meaning |
| --------- | --------------- | ------- |
| `200`     | pubsub.busAck   | ok      |
| `default` | problem-details | refused |

`200` body — 4 fields.

| Field       | In   | Type             | Always | Description                                                                                                                                |
| ----------- | ---- | ---------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `duplicate` | body | boolean          | —      | Duplicate is true when JetStream deduplicated the message by its Nats-Msg-Id instead of storing it again.                                  |
| `ok`        | body | boolean          | —      | OK is true when the bus accepted the message.                                                                                              |
| `seq`       | body | integer (uint64) | —      | Seq is the message's sequence in that stream.                                                                                              |
| `stream`    | body | string           | —      | Stream is the stream that stored the message — absent when no stream captures the subject and the message went out core (fire-and-forget). |

Failure carries the platform error shape — see [Errors](https://docs.hanzo.ai/docs/errors).

## Examples

**CLI**

```bash
hanzo pubsub publish
```

**SDK**

**.ts**

```ts
import { Configuration, PubsubApi } from 'hanzoai';

const api = new PubsubApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.postPubsubPublish({ data: "<data>", headers: {} });
```

**.py**

```python
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import PubsubApi

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = PubsubApi(client).post_pubsub_publish(data="<data>", headers={})
```

**.go**

```go
cfg := hanzoai.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := hanzoai.NewAPIClient(cfg)

resp, _, err := client.PubsubAPI.PostPubsubPublish(context.Background()).Execute()
if err != nil {
	return err
}
```

**.rs**

```rust
use hanzo_client::apis::{configuration::Configuration, pubsub_api};

let mut cfg = Configuration::new();
cfg.bearer_access_token = std::env::var("HANZO_API_KEY").ok();

let result = pubsub_api::post_pubsub_publish(&cfg, Default::default()).await?;
```

**.java**

```java
import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.PubsubApi;

ApiClient client = new ApiClient();
client.setBearerToken(System.getenv("HANZO_API_KEY"));

var result = new PubsubApi(client).postPubsubPublish();
```

**HTTP**

```bash
curl -X POST https://api.hanzo.ai/v1/pubsub/publish \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "data": "<data>",
       "headers": {}
     }'
```

**MCP**

MCP declares no tool for **pubsub** — `tools/list` on `https://api.hanzo.ai/v1/mcp` names the products it does reach. Use HTTP or an SDK.

---

[Pubsub API](https://docs.hanzo.ai/docs/openapi/pubsub) · [All Hanzo APIs](https://docs.hanzo.ai/docs/openapi) · [Interactive reference](https://docs.hanzo.ai/docs/openapi/reference)
