# Autoke API

> Create a post draft, review it, and then publish immediately or schedule it for connected social media channels.

## Get started in five minutes

### 1. Create an API key

1. Sign in to your [Autoke account](https://autoke.ai/en/account).
2. Open **API keys** and select **Create key**.
3. Copy the key beginning with `ak_live_` and store it securely.

The full key is shown only once. Treat it like a password and never expose it in browser code or a public repository. An active subscription is required.

A key created for a subuser can use only the channels connected to that brand. If you manage several brands, use a separate key for each one.

> **Recommended**
>
> For automated or continuous API calls, enable [Auto Top-Up](https://autoke.ai/en/billing) to prevent jobs from stopping when credits run low. Auto Top-Up is available for supported accounts.

### 2. Create your first post draft

Send your API key and JSON content type with every request.

```bash
curl https://autoke.ai/api/v3/generate-post \
  -H "Authorization: Bearer ak_live_your_key" \
  -H "Content-Type: application/json" \
  -d '{
	"instruction": "Write a friendly post about our summer peach ade",
    "platforms": ["threads"],
    "language": "English"
  }'
```

A successful request returns a draft without publishing it. Review and edit the content before moving on.

```json
{
	"success": true,
	"data": {
		"content": "We spend more time peeling these peaches than actually making the drink. Using only ripe fruit means we have to hand-peel them to keep the texture right for the syrup. \n\nIf you use a machine or blanch them for too long, they lose that specific floral scent that makes the ade work. The sugar ratio has to stay at exactly 1:1 to balance the acidity of the lemon.\n\nIt is a lot of prep for one drink.",
		"timeSlot": "Lunch Break"
	}
}
```

This response was generated by the exact request above. `timeSlot` indicates when the post is most likely to reach its audience.

### 3. Publish the approved post

- Publish now: `POST /api/v3/post-now`
- Choose a future time: `POST /api/v3/schedule-post`

> **Important**
>
> Connect the target platform channels in Autoke before sending a publishing request.

Instagram requires an image or video.

## What can you build?

### Create a post draft

`POST /api/v3/generate-post`

Describe the topic and tone in natural language with `instruction`. The draft is returned in `data.content` and uses 20 credits.

### Create an image for a post

`POST /api/v3/generate-image`

Describe the scene in `prompt`. To edit an existing image, include `imageURLs` and `mode: "edit"`. Uses 300 credits.

### Create a profile bio

`POST /api/v3/generate-bio`

Describe the desired bio in `instruction` or provide an existing bio in `content`. Brand and platform details produce a more relevant result. Uses 20 credits.

### Publish now or schedule

`POST /api/v3/post-now` or `POST /api/v3/schedule-post`

Supported platforms are `x`, `facebook`, `instagram`, and `threads`. Check `results` for the outcome on each platform.

## Handle errors

A failed generation request returns `success: false` with an HTTP status code. `error.code` matches that status, while `error.message` explains the specific cause.

```json
{
	"success": false,
	"error": {
		"code": 401,
		"message": "Invalid API key"
	}
}
```

- `400 Bad Request`: A required value is missing or invalid. Review the operation's required fields and request example.
- `401 Unauthorized`: The API key is missing or invalid. Check for the `Authorization: Bearer YOUR_API_KEY` format.
- `402 Insufficient Credit`: The account does not have enough credits for generation. Check the balance, and enable Auto Top-Up for continuous API calls.
- `403 Subscription Required`: The current subscription cannot use API keys. Check the subscription status.
- `500 Server Error`: The server could not process the request. Try again later.

Publishing requests can succeed at the HTTP level while failing on one or more platforms. Check every item in `results`.

```json
{
	"success": false,
	"results": [
		{
			"platform": "instagram",
			"success": false,
			"error": "No instagram channel found"
		}
	],
	"postIDs": []
}
```

## Learn more

- [Interactive API documentation](https://autoke.ai/en/api-docs)
- [OpenAPI 3.1 document](https://autoke.ai/openapi/en.json)
- [Autoke account](https://autoke.ai/en/account)
