# API overview

The Genuin API has two parts:

- **The third-party API**, under `/api/thirdparty`. It creates communities and groups, adds members and moderators, and posts videos for your brand.
- **The Business Account API (v1)**, at `https://api.begenuin.com/v1`. It creates, configures and runs a Business Account. Account owners, partners and aggregators acting for many accounts, and AI agents all use it.

This page covers what every call has in common: base URLs, authentication, the status check, responses and errors, and rate limits. For each call, see the two collections:

- [GET APIs](https://begenuin.com/developers/developer-resources/api/get-apis): every call that reads.
- [POST APIs](https://begenuin.com/developers/developer-resources/api/post-apis): every call that creates or changes something, plus PUT, PATCH and DELETE.

## Base URLs

| API | Production | QA |
| --- | --- | --- |
| Third-party API | https://api.begenuin.com/api/thirdparty | https://api.qa.begenuin.com/api/thirdparty |
| Business Account API (v1) | https://api.begenuin.com/v1 | Sandbox keys on the production URL |

Send JSON with the `Content-Type: application/json` header. Without that header, the server doesn't parse the body and returns `412 Precondition Failed`.

## Authentication

### Third-party API: access token

Exchange your brand's `api_key` and `api_secret` for a `gn-access-token`, then send it as a bearer token on every other third-party call. The token acts as your brand's owner account, so anything you do with it is done as that account.

You need an `api_key` and an `api_secret` for your brand. The Genuin team issues one pair per brand and environment: a 48-character hexadecimal key and a 32-character hexadecimal secret. The pair works only while your brand is active.

> **Caution** Your api_secret is a server-side credential. Don't put it in browser JavaScript, mobile apps or any code you ship to users. Keep it in an environment variable or a secrets manager, and call the token endpoint from your backend only.

```bash title="cURL"
curl -i -X POST https://api.begenuin.com/api/thirdparty/auth \
  -H "Content-Type: application/json" \
  -d '{
    "api_key": "<<YOUR_API_KEY>>",
    "api_secret": "<<YOUR_API_SECRET>>"
  }'
```

The endpoint takes no `Authorization` header. It returns `200 OK` with the access token in the `gn-access-token` response header and a refresh token in the `gn-refresh-token` header. The `-i` flag prints the headers.

```http title="Response headers"
HTTP/1.1 200 OK
Content-Type: application/json
gn-access-token: {{GN_ACCESS_TOKEN}}
gn-refresh-token: {{GN_REFRESH_TOKEN}}
```

```json title="Response body"
{
  "code": 200,
  "message": "Token Generated Successfully.",
  "data": {
    "user_id": "b12f13af-ef5a-4906-b0a0-2995e106200d",
    "login_source": "{{LOGIN_SOURCE}}",
    "device_type": null
  }
}
```

`data.user_id` is the UUID of your brand's owner account.

**Use the token.** Send it in the `Authorization` header with the `Bearer` scheme. One token serves every third-party endpoint.

```bash title="cURL"
curl -X POST https://api.begenuin.com/api/thirdparty/community/create \
  -H "Authorization: Bearer {{GN_ACCESS_TOKEN}}" \
  -H "Content-Type: application/json" \
  -d '{ "handle": "{{COMMUNITY_HANDLE}}", "name": "{{COMMUNITY_NAME}}" }'
```

**Token lifetime.** An access token lasts 14 days in production and 3 hours in QA. A refresh token lasts 100 days in production and 24 hours in QA. Each call to the token endpoint creates a new session, and doesn't invalidate the tokens you already hold. When an access token expires, calls return `401` with code `1003`. Call the token endpoint again, or exchange the refresh token for a new pair:

```bash title="cURL"
curl -i -X POST https://api.begenuin.com/api/v4/auth/session/refresh \
  -H "Authorization: Bearer {{GN_REFRESH_TOKEN}}"
```

The response carries a new `gn-access-token` and `gn-refresh-token` in its headers. Don't send an `x-brand-id` header with this request: a mismatched brand ID makes it fail with `401`.

**Rotate credentials.** To replace a token you think was exposed, call the token endpoint again and switch to the new value; the old token stays valid until it expires, so ask the Genuin team if you need it revoked. To replace the `api_key` and `api_secret`, contact the Genuin team. The old pair stops working as soon as the new one is issued.

### Brand API key

Two calls and the SDKs use your brand API key instead of a token: [Delete a member account](https://begenuin.com/developers/developer-resources/api/delete-a-member-account) and the community lookup in [GET APIs](https://begenuin.com/developers/developer-resources/api/get-apis). Copy the key from your Business Account under **Build** > **Publish Brand Community** > **SDK Integration**.

| Credential | Issued by | Used for |
| --- | --- | --- |
| api_key and api_secret | The Genuin team, one pair per brand and environment | Exchanged for a gn-access-token on your server |
| gn-access-token | POST /api/thirdparty/auth | Every other third-party call |
| Brand API key | Your Business Account | The SDKs, Delete a member account, and the community lookup |

### Business Account API (v1): API keys and OAuth

| Who | How | Scope |
| --- | --- | --- |
| The account owner or a teammate | An API key from Settings > Developers, a sandbox key at sign-up and a live key at launch, scoped to the account and the key holder's role | One Business Account |
| A partner, aggregator or platform acting for many accounts | OAuth 2.0 client credentials: POST /v1/oauth/token with client_id, client_secret, scope and the account_id to act on. Tokens expire in 1 hour | Every account that granted the client access |
| A partner provisioning a new customer | POST /v1/accounts creates the Business Account, its first brand and a sandbox key, and returns the owner's verification link | The created account |
| An AI buyer agent | AdCP endpoints with a buyer key | Packages only |

Scopes: `account:read`, `account:write`, `brand:read`, `brand:write`, `content:write`, `network:write`, `members:write`, `partners:write`, `monetize:write`, `reports:read`, `intelligence:act`. A key or token never exceeds the role it was issued for. `intelligence:act` lets an integration raise proposals, but not approve them unless it also holds the matching write scope.

```bash title="cURL"
curl -X POST https://api.begenuin.com/v1/oauth/token \
  -d client_id=$CLIENT_ID -d client_secret=$CLIENT_SECRET \
  -d account_id=acc_123 -d scope="brand:write network:write reports:read"
```

Send the token as `Authorization: Bearer <token>`. Rotate a key with `POST /v1/keys/{keyId}:rotate`; the old key keeps working for 24 hours.

## Status check

Check that the API is up with `GET /healthcheck`. It takes no authentication.

```bash title="cURL"
curl https://api.begenuin.com/healthcheck
```

```json title="Response"
{ "message": "Server is running." }
```

A `200` with this body means the API server is answering. It doesn't check your credentials: to confirm those work, request a token from `POST /api/thirdparty/auth`. Use the health check for uptime monitoring, and before you retry after a `1099` or a `422`.

## Responses and errors

Third-party responses share one shape: `code`, `message` and `data`. A successful call sets `code` to the number `200`. An error sets it to a string, such as `"5218"`, and comes with an HTTP status in the 4xx range.

```json title="Error response"
{
  "code": "5218",
  "message": "The community you are looking for is no longer available.",
  "data": {}
}
```

| Field | Type | Description |
| --- | --- | --- |
| code | string | Genuin's error code. It identifies the cause more precisely than the HTTP status, and it's the value to match on. |
| message | string | A sentence for logs and support tickets. Some messages carry a literal XXXX- prefix, such as XXXX-[Invalid Use of API]. |
| data | object | Usually {}. A few errors add details: data.err_msg lists rejected link-out URLs, and data.video_id names the video a duplicate upload matched. |

Business Account API (v1) errors are JSON with `code`, `message` and `docs_url`.

### Validation errors

Each third-party endpoint checks the body against its schema before doing anything. How it reports a failure differs by endpoint.

| Endpoint | HTTP status | What comes back |
| --- | --- | --- |
| POST /auth | 412 | code 5166 when a field is missing or isn't a string; 5272 with data.err_msg when the body isn't valid JSON |
| POST /community/create | 400 | No code or message. data.message names the failing fields, such as handle or type |
| POST /group/create, POST /users/conversation/reply, PATCH /update_conversation | 400 | {"data": {}} and nothing else. The failing field isn't reported |
| POST /community/add_users, POST /community/add_moderators | 412 | code 5166 |

For the endpoints that return an empty body, compare your request with the endpoint's parameters table. The usual causes are a value of the wrong type, a value outside its allowed set, or a missing required field.

### Error codes

Codes are shared across the third-party endpoints.

| HTTP status | code | Meaning | Returned by |
| --- | --- | --- | --- |
| 400 | 1099 | The server failed while handling a valid request. Message: An unexpected error occurred processing the request | Any endpoint |
| 401 | 1003 | Missing, expired or revoked token. Message: authentication is required. | Any endpoint that takes a token |
| 401 | 5033 | The token wasn't issued by the token endpoint, such as a device token from an app session. Message: Invalid or tempered token. | Any endpoint that takes a token |
| 401 | 5159 | The account can't make this call: it isn't a member of the community, isn't the group's owner or an admin, or sent a brand_id it isn't a user of. Message: Invalid Use of API | Create a community, create a group, update a group |
| 403 | 5230 | A community or group setting excludes the account, such as who can create groups or who can post. Message: XXXX-[Access Denied]. | Create a group, post a video |
| 403 | 5243 | The community or group belongs to a brand outside your network. Message: XXXX-[given user's brand_id is being conflicted with asked content's brand_id]. | Create a group, post a video |
| 404 | 5044 | No group with that chat_id, or it's deleted or flagged. Message: Can't find group. It may have been deleted by you or the other person in the group. | Post a video, update a group |
| 404 | 5218 | No community with that id, or it's deleted. Message: The community you are looking for is no longer available. | Add members, add moderators |
| 404 | 5235 | No active brand matches the credentials or the token. Message: Brand not exists. | POST /auth, any endpoint that takes a token |
| 404 | 5025 | The brand's owner account is inactive. Message: The user you are looking for is no longer available. | POST /auth |
| 409 | 5057 | The video_name or message_id was posted before. Message: You have already replied to this video. | Post a video |
| 409 | 5156 | The opening video's video_name was posted before; data.video_id names the earlier post. Message: You have already published this video | Create a group |
| 409 | 5167 | A group with the same share string exists. Message: XXXX-[You have already published this group] | Create a group |
| 409 | 5216 | The handle is taken. Message: XXXX-[community handle already exists.] | Create a community |
| 409 | 5217 | The profile image file name is used by another community. Message: XXXX-[community dp already exists.] | Create a community |
| 412 | 5166 | The request breaks a rule: wrong action ids, a missing field, many users to many communities, a link-out URL outside your allowed domains, or an account without the required role. Message: XXXX-[Invalid Use of API] | POST /auth, create a community, create a group, post a video, add members, add moderators |
| 412 | 5174 | The signed-URL request used a content type other than video, image, audio or text. Message: Pre Condition failed | Upload step of post a video |
| 412 | 5227 | The community already has a welcome group. Message: XXXX-[welcome group already exists] | Create a group |
| 412 | 5272 | The body isn't valid JSON; data.err_msg explains. Message: Pass payload is invalid. please read err_msg for more details | POST /auth |
| 422 | 5023 | The server couldn't sign an upload URL. Message: Could not fetch credentials. | Upload step of post a video |
| 422 | 5059 | The post couldn't be saved. Message: Error in sending reply. | Post a video |
| 422 | 5158 | The update couldn't be applied. Message: Could not update the group. | Update a group |

### What to retry

| HTTP status | Retry | Why |
| --- | --- | --- |
| 400 with code 1099, and 422 | Once, after a short wait | The request was valid and the server failed. A second attempt usually succeeds. |
| 400 from validation, 401, 403, 404, 412 | No | The request itself is the problem. Fix it before you send it again. |
| 409 | No | The record already exists. Treat it as success when the earlier call was yours. |

Treat a `422` or a `1099` on a write as indeterminate: the change may have been saved. Retrying is still safe, because the duplicate checks turn a second save into a `409`. Pass your own `message_id` when you post a video, and keep the same `handle` when you create a community. A repeated call is then rejected as a duplicate instead of creating a second record. A repeated group update is harmless: fields already at the new value come back with `false` in their `_updated` flag.

When you contact the Genuin team about an error, include the HTTP status, the `code`, the `message`, the endpoint and the request time in UTC. A `1099` can only be traced on the server side, by its timestamp.

## Rate limits

| API | Limit |
| --- | --- |
| Third-party API | None. A retry only needs to wait for a server-side failure to clear; a second or two is enough. |
| Business Account API (v1) | 600 requests per minute per key or token, and 60 per minute for report queries. Every response carries X-RateLimit-Remaining. |

## Business Account API conventions

- Ids are prefixed: `acc_`, `brd_`, `plc_`, `cmt_`, `vid_`, `fd_`, `mbr_`, `prt_`, `agr_`, `prp_`.
- List calls page with `cursor` and `limit`. Filters are query parameters.
- A write that your Business Account would ask you to confirm returns `202` with a `proposal` object. `POST /v1/proposals/{proposalId}:approve` applies it and `:decline` discards it. See [Supervised Intelligence Autonomy and Approvals](https://begenuin.com/developers/browse-by-products/supervised-intelligence/supervised-intelligence-autonomy-and-approvals).
- Every change emits a webhook event, such as `proposal.created`, `placement.published` or `partner.accepted`. See [Webhooks and events](https://begenuin.com/developers/developer-resources/api/webhooks-and-events).

## Limitations

- **Codes aren't unique across the platform.** `5243` also names an unrelated server error elsewhere. On the third-party endpoints it always means the brand mismatch above.
- **Messages are English only**, and some carry the literal `XXXX-` prefix. Map codes to your own text rather than showing messages to members.
- **No test credential pair.** Use the QA base URL with the credentials issued for QA.

## Next

- [GET APIs](https://begenuin.com/developers/developer-resources/api/get-apis): every read call.
- [POST APIs](https://begenuin.com/developers/developer-resources/api/post-apis): every call that creates or changes something.
- [Environments, credentials, and test data](https://begenuin.com/developers/developer-resources/overview/environments-credentials-and-test-data)
