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

# Generate Blog Meta Elements

> Generate images, excerpt, category, and tags for blog posts

## Overview

Generate complete blog post metadata including images, excerpt, category, and tags using AI. This endpoint uses advanced AI models to create professional blog metadata.

<Endpoint method="post" url="/blog/generate" />

## Request Body

<ParamField body="title" type="string" required>
  The title of your blog post. This is used to generate all elements.
</ParamField>

<ParamField body="api_key" type="string" required>
  Your GistMag API key
</ParamField>

<ParamField body="content" type="string" optional>
  Optional blog post content. Providing content helps generate more accurate and relevant results.
</ParamField>

<ParamField body="image_style" type="string" default="realistic">
  The style of images to generate. Options:

  * `realistic`: Photorealistic images
  * `illustration`: Artistic illustrations
  * `abstract`: Abstract designs
  * `minimalist`: Simple, clean designs
  * `photographic`: High-quality photographs
</ParamField>

<ParamField body="language" type="string" default="en">
  Language code for the generated content (default: en)
</ParamField>

<ParamField body="source" type="string" optional>
  Source identifier for tracking (web, api, extension, wordpress, shopify, batch)
</ParamField>

## Example Request

### cURL

```bash theme={null}
curl -X POST https://api.gistmag.co.uk/blog/generate \
  -H "Content-Type: application/json" \
  -d '{
    "title": "10 Tips for Better Productivity",
    "content": "In this article, we explore proven strategies to improve your productivity and get more done in less time...",
    "api_key": "your_api_key_here",
    "image_style": "realistic",
    "language": "en"
  }'
```

### Python

```python theme={null}
import requests

url = "https://api.gistmag.co.uk/blog/generate"

payload = {
    "title": "10 Tips for Better Productivity",
    "content": "In this article, we explore proven strategies to improve your productivity and get more done in less time...",
    "api_key": "your_api_key_here",
    "image_style": "realistic",
    "language": "en"
}

headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

if response.status_code == 200:
    data = response.json()
    print(f"Generated {len(data['images'])} images")
    print(f"Excerpt: {data['excerpt']}")
    print(f"Category: {data['category']}")
    print(f"Tags: {', '.join(data['tags'])}")
else:
    print(f"Error: {response.json()}")
```

### JavaScript

```javascript theme={null}
const response = await fetch('https://api.gistmag.co.uk/blog/generate', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    title: '10 Tips for Better Productivity',
    content: 'In this article, we explore proven strategies to improve your productivity...',
    api_key: 'your_api_key_here',
    image_style: 'realistic',
    language: 'en'
  })
});

const data = await response.json();

if (response.ok) {
  console.log(`Generated ${data.images.length} images`);
  console.log(`Excerpt: ${data.excerpt}`);
  console.log(`Category: ${data.category}`);
  console.log(`Tags: ${data.tags.join(', ')}`);
} else {
  console.error('Error:', data);
}
```

## Image Generation

Images are generated using **Nano Banana** (Google Gemini Image Generation API) and automatically uploaded to Supabase Storage. Each image is returned as a public URL that can be directly used in your application or downloaded.

<Info>
  All images are hosted on Supabase Storage and are publicly accessible via the returned URLs. Images are generated in the style you specify and optimized for web use.
</Info>

## Response

<ResponseField name="images" type="array">
  Array of generated images (up to 3 images)
</ResponseField>

<ResponseField name="images[].url" type="string">
  Public URL of the generated image (hosted on Supabase Storage). Images are generated using Nano Banana (Google Gemini) and automatically uploaded to storage.
</ResponseField>

<ResponseField name="images[].style" type="string">
  The style of the image (realistic, illustration, abstract, minimalist, photographic)
</ResponseField>

<ResponseField name="images[].description" type="string">
  Description of what the image represents
</ResponseField>

<ResponseField name="excerpt" type="string">
  A concise 2-3 sentence summary of the blog post (max 200 characters)
</ResponseField>

<ResponseField name="category" type="string">
  An appropriate category name for the blog post (e.g., "Technology", "Health", "Business")
</ResponseField>

<ResponseField name="tags" type="array<string>">
  Array of 5-8 relevant tags for the blog post
</ResponseField>

<ResponseField name="generated_at" type="string">
  ISO 8601 timestamp of when the content was generated
</ResponseField>

### Example Response

```json theme={null}
{
  "images": [
    {
      "url": "https://eutekssvzhtkwzperkzb.supabase.co/storage/v1/object/public/blog-images/1234567890-abc123.png",
      "style": "realistic",
      "description": "Create a realistic style image representing: 10 Tips for Better Productivity..."
    },
    {
      "url": "https://eutekssvzhtkwzperkzb.supabase.co/storage/v1/object/public/blog-images/1234567891-def456.png",
      "style": "realistic",
      "description": "Create a realistic style image representing: 10 Tips for Better Productivity..."
    },
    {
      "url": "https://eutekssvzhtkwzperkzb.supabase.co/storage/v1/object/public/blog-images/1234567892-ghi789.png",
      "style": "realistic",
      "description": "Create a realistic style image representing: 10 Tips for Better Productivity..."
    }
  ],
  "excerpt": "Discover 10 proven strategies to boost your productivity and accomplish more in less time. Learn practical tips for time management, focus, and efficiency.",
  "category": "Productivity",
  "tags": [
    "productivity",
    "time management",
    "efficiency",
    "work-life balance",
    "focus",
    "organization",
    "tips",
    "self-improvement"
  ],
  "generated_at": "2024-12-20T12:00:00.000Z"
}
```

## Error Responses

<ResponseField name="error" type="string">
  Error type
</ResponseField>

<ResponseField name="message" type="string">
  Detailed error message
</ResponseField>

### Common Errors

* `400 Bad Request`: Invalid request parameters (e.g., missing title, invalid image\_style)
* `401 Unauthorized`: Invalid or missing API key
* `402 Payment Required`: Insufficient credits (requires 3 credits per generation)
* `500 Internal Server Error`: Server error processing the request

### Example Error Response

```json theme={null}
{
  "error": "Insufficient Credits",
  "message": "You don't have enough credits. Current balance: 1. Please purchase more credits or upgrade your plan."
}
```

## Best Practices

1. **Provide Content When Possible**: Including the blog post content helps generate more accurate excerpts, categories, and tags
2. **Choose Appropriate Image Style**: Select an image style that matches your blog's aesthetic
3. **Review Generated Content**: Always review and edit the generated content to ensure it matches your brand voice
4. **Handle Image URLs**: Generated image URLs are temporary - download and host them on your own server for permanent use
5. **Credit Management**: Each generation costs 3 credits, so ensure you have sufficient credits before making requests

## Rate Limits

The Blog Meta Generator follows the same rate limits as other GistMag API endpoints. Check your subscription tier for specific limits.
