This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Not being able to generate images, I am pro user but I am not able to generate images ? can someone guide me? #141
Unanswered
aavhad1910
asked this question in
Q&A
Replies: 1 comment
-
The Perplexity API does not have the ability to generate images like it does in the main Perplexity UI. The You will also need to be in tier 2 for it to actually return images it found on the web, see their usage tier documentation. Just a side note, if you are already using Python, I highly recommend just using the OpenAI API, as Perplexity's API is compatible with it. For example, if you were tier 2, you could ask a question and get internet images as follows: import os
from openai import OpenAI
client = OpenAI(api_key=os.environ.get("PPLX_API_KEY"), base_url="https://api.perplexity.ai")
completion = client.chat.completions.create(
model="sonar-pro",
messages=[
{
"role": "user",
"content": "What is the most recent version of Python?"
}
],
extra_body={"return_images": True}
)
print(completion.choices[0].message) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
import requests
import json
import random
from datetime import datetime
def generate_facebook_post(api_key, topic="positivity"):
"""Generates post content and image using Perplexity AI"""
try:
# Generate text post
post = generate_post_text(api_key, topic)
if not post:
return None
def generate_post_text(api_key, topic):
"""Generates post text using Perplexity's chat API"""
url = "https://api.perplexity.ai/chat/completions"
def generate_and_save_image(api_key, post_text, topic):
"""Generates and saves image using Perplexity's API"""
url = "https://api.perplexity.ai/chat/completions"
def save_text_to_file(content):
"""Saves text content to a file with timestamp"""
filename = f"facebook_post_{get_timestamp()}.txt"
with open(filename, 'w') as f:
f.write(content)
return filename
def get_timestamp():
"""Generates timestamp for filenames"""
return datetime.now().strftime("%Y%m%d_%H%M%S")
Example usage
if name == "main":
API_KEY = YOUR_API_KEY
Beta Was this translation helpful? Give feedback.
All reactions