generate
Generate new social post and rewrite post using AI
Creating the text for social media post can be difficult: writing the copy, hashtag, correct length, and emojis. Or if you have an existing social post and need variations — the social networks do not like duplicate posts.
The subdomain used for these calls is api.ayrshare.com
instead of the standard app.ayrshare.com.
Max Pack Required.
❗Click the › in the endpoint to view details.
POST Generate a Post Text
POST
https://api.ayrshare.com/api/generate/post
Generate a new social post using AI. You can either provide text or images to create the social media post. Token limits applicable.
Headers
Request Body
{
"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! 🙌 #newshow #onSale #fashionable #colormebeautiful 🌈",
"usage": 98, // Tokens used for this call
"totalMonthlyUsage": 733 // Total tokens used for the month
}
{
"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
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://docs.ayrshare.com/rest-api/endpoints"
}
Request Examples
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
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({
post: "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);
import requests
payload = {'post': '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
$curl = curl_init();
$data = array (
"post" => "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;
POST Rewrite a Post
POST
https://api.ayrshare.com/api/generate/rewrite
Generate variations of a social media posts using AI. Token limits applicable.
Headers
Request Body
{
"status": "success",
"post": "Kali melts the heart, even when the rest of the day is freezing. Happy International Polar Bear Day to the largest land carnivore and the biggest, furriest part of the Zoo’s bear community! \nOur resident polar bear Kali (pronounced “Cully”) is a wild-born bear that was born off of the northwest coast of Alaska. He was named by the people of the Native Village of Point Lay, who rescued him. \"Kali\" is the Inupiaq name for Point Lay. Eventually, the U.S. Fish and Wildlife",
"rewrites": [
"❄️🐻 Kali, the lovable polar bear, warms our hearts on this #InternationalPolarBearDay. Fun fact: he was named after Inupiaq village, Point Lay! #FurryZooCommunity 🐾",
"Happy #InternationalPolarBearDay to Kali, the largest land carnivore of the Zoo community! Even on freezing days, Kali steals our hearts with his adorable antics. 🐻❤️",
"Meet Kali, the wild-born polar bear with a heart-melting charm. 🐾❄️ Sending love on this #InternationalPolarBearDay to the Zoo's fluffiest resident. 🐻❤️",
"On #InternationalPolarBearDay, we celebrate Kali, the furry wonder from the largest land carnivore family of the Zoo. 🐾🐻 He was named after an Inupiaq village, Point Lay!🌟",
"Kali, the Zoo's beloved polar bear, steals our hearts with his playful spirit, as we celebrate #InternationalPolarBearDay. 🐻❤️ Born off the Alaskan coast, he's a true warrior! 💪🌟"
],
"usage": 98, // Tokens used for this call
"totalMonthlyUsage": 733 // Total tokens used for the month
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://docs.ayrshare.com/rest-api/endpoints"
}
Request Examples
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"post": "Kali melts the heart, even when the rest of the day is freezing. Happy International Polar Bear Day to the largest land carnivore and the biggest, furriest part of the Zoo’s bear community! \nOur resident polar bear Kali (pronounced “Cully”) is a wild-born bear that was born off of the northwest coast of Alaska. He was named by the people of the Native Village of Point Lay, who rescued him. \"Kali\" is the Inupiaq name for Point Lay. Eventually, the U.S. Fish and Wildlife"}' \
-X POST https://api.ayrshare.com/api/generate/rewrite
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/generate/rewrite", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({
post: "Kali melts the heart, even when the rest of the day is freezing. Happy International Polar Bear Day to the largest land carnivore and the biggest, furriest part of the Zoo’s bear community! \nOur resident polar bear Kali (pronounced “Cully”) is a wild-born bear that was born off of the northwest coast of Alaska. He was named by the people of the Native Village of Point Lay, who rescued him. \"Kali\" is the Inupiaq name for Point Lay. Eventually, the U.S. Fish and Wildlife", // required
}),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'post': 'Kali melts the heart, even when the rest of the day is freezing. Happy International Polar Bear Day to the largest land carnivore and the biggest, furriest part of the Zoo’s bear community! \nOur resident polar bear Kali (pronounced “Cully”) is a wild-born bear that was born off of the northwest coast of Alaska. He was named by the people of the Native Village of Point Lay, who rescued him. \"Kali\" is the Inupiaq name for Point Lay. Eventually, the U.S. Fish and Wildlife'}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.post('https://api.ayrshare.com/api/generate/rewrite',
json=payload,
headers=headers)
print(r.json())
<?php
$curl = curl_init();
$data = array (
"post" => "Kali melts the heart, even when the rest of the day is freezing. Happy International Polar Bear Day to the largest land carnivore and the biggest, furriest part of the Zoo’s bear community! \nOur resident polar bear Kali (pronounced “Cully”) is a wild-born bear that was born off of the northwest coast of Alaska. He was named by the people of the Native Village of Point Lay, who rescued him. \"Kali\" is the Inupiaq name for Point Lay. Eventually, the U.S. Fish and Wildlife"
);
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.ayrshare.com/api/generate/rewrite',
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;
POST Transcribe a Video
POST
https://api.ayrshare.com/api/generate/transcription
Provide a transcription and title of a video file using AI. This transcription can then be used in the /generate/post to create a social media summary of the video. The title can be used for post the video, such a for YouTube which requires a title.
⮕ The video must have been previously upload to Ayrshare with /media. Videos not hosted by Ayrshare will be rejected.
⮕ Video max size 500GB and 10 minute duration.
Headers
Request Body
{
"status": "success",
"transcript": "This is your last chance. After this, there is no turning back. You take the blue pill the story ends you wake up in your bed and believe whatever you want to be. You take the red pill you stay in Wonderland. And I show you how deep the rabbit hole goes.",
"transcriptArray": [
"This is your last chance.",
"After this, there is no turning back.",
"You take the blue pill the story ends you wake up in your bed and believe whatever you want to be. You take the red pill you stay in Wonderland.",
"And I show you how deep the rabbit hole goes."
],
"videoTitle": "Choose Wisely: Blue Pill or Red Pill Adventure Awaits!",
"wordCount": 52
}
Request Examples
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"videoUrl": "https://img.ayrshare.com/random/landscape5.mp4"}' \
-X POST https://api.ayrshare.com/api/generate/transcription
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/generate/transcription", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({
videoUrl: "https://img.ayrshare.com/random/landscape5.mp4", // required
}),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'videoUrl': 'https://img.ayrshare.com/random/landscape5.mp4'}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.post('https://api.ayrshare.com/api/generate/transcription',
json=payload,
headers=headers)
print(r.json())
<?php
$curl = curl_init();
$data = array (
"videoUrl" => "https://img.ayrshare.com/random/landscape5.mp4"
);
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.ayrshare.com/api/generate/transcription',
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;
Transcribe Video Guide
POST Translate Post Text
POST
https://app.ayrshare.com/api/generate/translate
Translate text for a post to over 100 different languages using AI. The current language is automatically detected and translated to the specified language.
Headers
Request Body
{
"status": "success",
"translatedText": "Nos vamos a las carreras",
"originalText": "Off we go to the races",
"language": "es"
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://docs.ayrshare.com/rest-api/endpoints"
}
POST Generate alt text for an image
POST
https://api.ayrshare.com/api/generate/altText
Create AI-generated alt text for your images. Choose the language to write the alt text and keywords to include in the alt text.
Headers
Request Body
{
"status": "success",
"altText": "A ghostbusters vehicle driving through a field.",
"url": "https://img.ayrshare.com/012/gb.jpg"
}
{
"action": "upload",
"status": "error",
"code": 115,
"message": "An error occurred uploading your file, such as a timeout at the social network. Please try your post again with the /retryPost endpoint.",
}
Request Examples
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"url": "https://img.ayrshare.com/012/gb.jpg"}' \
-X POST https://api.ayrshare.com/api/generate/altText
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/generate/altText", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({
url: "https://img.ayrshare.com/012/gb.jpg", // required
}),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'url': 'https://img.ayrshare.com/012/gb.jpg'}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.post('https://api.ayrshare.com/api/generate/altText',
json=payload,
headers=headers)
print(r.json())
<?php
$curl = curl_init();
$data = array (
"url" => "https://img.ayrshare.com/012/gb.jpg"
);
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.ayrshare.com/api/generate/altText',
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;
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Text.Json;
class Program
{
// Replace 'YOUR_API_KEY' with your actual Ayrshare API key
private const string API_KEY = "YOUR_API_KEY";
private static readonly HttpClient client = new HttpClient();
static async Task Main(string[] args)
{
string imageUrl = "https://img.ayrshare.com/012/gb.jpg";
try
{
var result = await GenerateAltTextAsync(imageUrl);
Console.WriteLine("Generated Alt Text:");
Console.WriteLine(JsonSerializer.Serialize(result, new JsonSerializerOptions { WriteIndented = true }));
}
catch (Exception e)
{
Console.WriteLine($"An error occurred: {e.Message}");
}
}
static async Task<JsonElement> GenerateAltTextAsync(string imageUrl)
{
var url = "https://api.ayrshare.com/api/generate/altText";
var requestData = new { url = imageUrl };
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {API_KEY}");
var json = JsonSerializer.Serialize(requestData);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync(url, content);
if (!response.IsSuccessStatusCode)
{
throw new HttpRequestException($"HTTP error! status: {response.StatusCode}");
}
var responseBody = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<JsonElement>(responseBody);
}
}
POST Generate Sentiment Analysis
POST
https://app.ayrshare.com/api/generate/sentiment
Generate a sentiment analysis on a social media post or comment to understand if the text is positive, negative, or neutral and recommendations on improving the text for a more positive reaction.
Headers
Request Body
{
"status": "success",
"text": "These shoes aren't the best. The color has faded and they are uncomfortable to walk in.",
"sentimentAnalysis": {
"sentiment": "negative", // positive, negative, or neutral
"opportunities": [
"Improve color durability",
"Enhance comfort level"
],
"recommendations": [
{
"opportunity": "Improve color durability",
"recommendation": "Investigate and use higher-quality dyes or materials to prevent fading over time."
},
{
"opportunity": "Enhance comfort level",
"recommendation": "Review and possibly redesign the shoe's insole and cushioning to provide better support and comfort for walking."
}
]
}
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://docs.ayrshare.com/rest-api/endpoints"
}
Request Examples
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"text": "These shoes aren't the best. The color has faded and they are uncomfortable to walk in."}' \
-X POST https://api.ayrshare.com/api/generate/sentiment
const API_KEY = 'YOUR_API_KEY';
const analyzeTextSentiment = async (text) => {
try {
const response = await fetch('https://api.ayrshare.com/api/generate/sentiment', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ text })
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log('Sentiment Analysis Result:', data);
return data;
} catch (error) {
console.error('Error analyzing sentiment:', error.message);
throw error;
}
};
import requests
import json
API_KEY = 'YOUR_API_KEY'
def analyze_text_sentiment(text):
url = 'https://api.ayrshare.com/api/generate/sentiment'
headers = {
'Authorization': f'Bearer {API_KEY}',
'Content-Type': 'application/json'
}
data = {'text': text}
try:
response = requests.post(url, headers=headers, json=data)
response.raise_for_status() # Raises a HTTPError if the status is 4xx, 5xx
result = response.json()
print('Sentiment Analysis Result:', json.dumps(result, indent=2))
return result
except requests.exceptions.RequestException as e:
print('Error analyzing sentiment:', e)
raise
<?php
$API_KEY = 'YOUR_API_KEY';
function analyzeTextSentiment($text) {
global $API_KEY;
$url = 'https://api.ayrshare.com/api/generate/sentiment';
$headers = [
'Authorization: Bearer ' . $API_KEY,
'Content-Type: application/json'
];
$data = json_encode(['text' => $text]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch)) {
echo 'Error analyzing sentiment: ' . curl_error($ch);
return null;
}
curl_close($ch);
if ($httpCode >= 200 && $httpCode < 300) {
$result = json_decode($response, true);
echo "Sentiment Analysis Result:\n";
print_r($result);
return $result;
} else {
echo "HTTP Error: " . $httpCode . "\n";
echo "Response: " . $response . "\n";
return null;
}
}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Text.Json;
class Program
{
private const string API_KEY = "YOUR_API_KEY";
private static readonly HttpClient client = new HttpClient();
static async Task Main(string[] args)
{
string textToAnalyze = "These shoes aren't the best. The color has faded and they are uncomfortable to walk in.";
try
{
var result = await AnalyzeTextSentimentAsync(textToAnalyze);
Console.WriteLine("Sentiment Analysis Result:");
Console.WriteLine(JsonSerializer.Serialize(result, new JsonSerializerOptions { WriteIndented = true }));
}
catch (Exception e)
{
Console.WriteLine($"An error occurred: {e.Message}");
}
}
static async Task<JsonElement> AnalyzeTextSentimentAsync(string text)
{
var url = "https://api.ayrshare.com/api/generate/sentiment";
var requestData = new { text = text };
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {API_KEY}");
var json = JsonSerializer.Serialize(requestData);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync(url, content);
if (!response.IsSuccessStatusCode)
{
throw new HttpRequestException($"HTTP error! status: {response.StatusCode}");
}
var responseBody = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<JsonElement>(responseBody);
}
}
Token Limits
For every API call made to AI endpoints, a certain number of "tokens" are used. These tokens are calculated based on the data you send and receive. Every month, your Max Pack and overall Ayrshare account are allocated a total of 300,000 tokens for Business plans, 100,000 for Premium Plus plans, and 50,000 for Premium plans. This allocation refreshes on the first day of each month. To see how many tokens a specific API call used, as well as your total usage for the month, please check the HTTP response.
Last updated