> ## Documentation Index
> Fetch the complete documentation index at: https://www.ayrshare.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate Post Text

> Generate a new social post using AI from text or image URLs, with options to add hashtags and emojis or keep the post to 280 characters for Twitter.

Generate a new social post using AI. You can either provide text or images to create the social media post. [Token limits](https://www.ayrshare.com/docs/apis/generate/overview.md#token-limits) applicable.

## Header Parameters

**Authorization** `string` *required*

[API Key](https://www.ayrshare.com/docs/apis/overview.md#authorization) of the Primary Profile.

Format: `Authorization: Bearer API_KEY`

## Body Parameters

**text** `string` *required*

Description of what the post should be about. For example: "A shoe sale happening Monday with specials on red, blue, and yellow shoes". Not required if `mediaUrls` parameter is included.

**mediaUrls** `array`

An array of image URLs to base the post text on. Required if `text` parameter not included.

**hashtags** `boolean` (default: true)

Add hashtags to the post.

**emojis** `boolean` (default: false)

Add emojis to the post.

**twitter** `boolean` (default: false)

Construct a post with 280 or few characters.

```bash cURL theme={"system"}
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"text": "This beautiful new shoe is on sale now. It comes in red, blue, or purple. Check it out today."}' \
-X POST https://api.ayrshare.com/api/generate/post
```

```javascript JavaScript theme={"system"}
const API_KEY = "API_KEY";

fetch("https://api.ayrshare.com/api/generate/post", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "Authorization": `Bearer ${API_KEY}`
      },
      body: JSON.stringify({
        text: "This beautiful new shoe is on sale now. It comes in red, blue, or purple. Check it out today.", // required
      }),
    })
      .then((res) => res.json())
      .then((json) => console.log(json))
      .catch(console.error);
```

```python Python theme={"system"}
import requests

payload = {'text': 'This beautiful new shoe is on sale now. It comes in red, blue, or purple. Check it out today.'}
headers = {'Content-Type': 'application/json',
        'Authorization': 'Bearer API_KEY'}

r = requests.post('https://api.ayrshare.com/api/generate/post',
    json=payload,
    headers=headers)

print(r.json())
```

```php PHP theme={"system"}
<?php

$curl = curl_init();
$data = array (
  "text" => "This beautiful new shoe is on sale now. It comes in red, blue, or purple. Check it out today."
);

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.ayrshare.com/api/generate/post',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => http_build_query($data),
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer API_KEY',
    'Accept-Encoding: gzip'
  ),
));

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

```json 200: Text theme={"system"}
{
    "status": "success",
    "post": "🎉🛍️ Introducing the stunning new shoes that's now on sale! You can choose from three different colors – red, blue, or purple – and trust us, they're all amazing! Don't miss out on this beauty and grab yours today! 🙌 #newshoe #onSale #fashionable #colormebeautiful 🌈",
    "usage": 98,                // Tokens used for this call
    "totalMonthlyUsage": 733    // Total tokens used for the month
}
```

```json 200: Image theme={"system"}
{
  "status": "success",
  "post": ["Ventured out on a serene walk today—a path less traveled but surrounded by the lush vibrancy of nature's finest. The perfect spot to reconnect with the earth and oneself. Where do your paths lead you?\n\n#NatureWalks #ExploreOutdoors #PeacefulPath"],
  "mediaUrls": ["https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"],
  "usage": 2295,
  "totalMonthlyUsage": 6987
}
```

```json 400: Bad Request theme={"system"}
{
  "action": "request",
  "status": "error",
  "code": 101,
  "message": "Missing or incorrect parameters. Please verify with the docs. .../ayrshare.com/rest-api/endpoints"
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.