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

# AI GIF Generator API

> Generate animated GIFs from text prompts with the Magic Hour API. Includes Python and Node.js examples, output formats, and credit costs.

export const ToolSection = ({type = "image", outputs = [], title = "", productSlug = "", apiSlug = ""}) => <>
    <CardGroup cols={2}>
      <Card title={`${title} API reference`} icon="webhook" horizontal href={`/api-reference/${type}-projects/${apiSlug}`}>
        Request fields, responses, and examples
      </Card>
      <Card title="API quickstart" icon="forward-fast" horizontal href="/get-started/quick-start">
        Install an SDK and complete your first generation
      </Card>
    </CardGroup>

    <p>
      Check <a href="/billing/overview">API pricing</a> and <a href="/api-reference/models">model credit costs</a>, then <a href={`https://magichour.ai/developer?tab=api-keys&ref=docs-tool-${apiSlug}&utm_source=docs&utm_medium=referral&utm_campaign=tools`}>create an API key</a>.
    </p>
    <p>
      To try {title} without code, use the <a href={`https://magichour.ai/products/${productSlug}${productSlug.includes("?") ? "&" : "?"}utm_source=docs&utm_medium=referral&utm_campaign=tools`}>browser tool</a>.
    </p>

    {outputs && outputs.length > 0 && <Tabs>
        {outputs.map((output, idx) => <Tab key={idx} title={`Example Output ${idx + 1}`}>
            <Frame>
              {type === "video" ? <video controls preload="metadata" playsInline className="rounded-lg h-80" src={`${output.src}#t=0.001`} type={`${output.src?.endsWith("mp4") ? 'video/mp4' : "video/webm"}`}>
                </video> : type === "audio" ? <audio controls preload="metadata" className="w-full" src={output.src}>
                  Your browser does not support the audio element.
                </audio> : <img height="320" className="rounded-lg h-80" src={output.src} alt={`${title} example output ${idx + 1}`} />}
            </Frame>
          </Tab>)}
      </Tabs>}

  </>;

## Overview

The AI GIF Generator API creates animated GIFs from a text prompt. Use it to add GIF generation to an application or automated media workflow. The endpoint accepts `style.prompt` and an `output_format` of `gif`, `mp4`, or `webm`.

To animate an existing image, use the [Image-to-Video API guide](/tools/video/image-to-video). The GIF endpoint does not accept an image input or a custom duration.

<Card title="Looking for the no-code GIF generator?" icon="wand-magic-sparkles" href="https://magichour.ai/products/ai-gif-generator">
  Create a GIF in your browser without writing code.
</Card>

<ToolSection
  title="AI GIF Generator"
  productSlug="ai-gif-generator"
  apiSlug="ai-gif-generator"
  type="image"
  outputs={[
{
  src: "/get-started/images/gifgeneratorexample1.gif",
},
{
  src: "/get-started/images/gifgeneratorexample2.gif",
},
]}
/>

## How It Works

1. **Write a prompt** - Describe the subject, action, and visual style in `style.prompt`
2. **Choose the file format** - Set `output_format` to `gif`, `mp4`, or `webm`
3. **Create the job** - Submit the request and wait for completion
4. **Download the output** - Save the completed animation from the returned download URL

## Use Cases

* **Social media content** - Create eye-catching animated posts
* **Reactions and memes** - Generate custom reaction GIFs
* **Marketing materials** - Animated graphics for campaigns
* **Website elements** - Dynamic visual content
* **Messaging** - Custom animated stickers and GIFs

## Code Examples

### Generate a GIF from text

<CodeGroup>
  ```python Python theme={null}
  from magic_hour import Client
  from os import getenv

  client = Client(token=getenv("MAGIC_HOUR_API_KEY"))
  result = client.v1.ai_gif_generator.generate(
      style={"prompt": "Cat fighting a lion, pixel art"},
      name="Ai Gif gif",
      output_format="gif",
      wait_for_completion=True,
      download_outputs=True,
      download_directory="."
  )

  if result.status == "complete":
      print(f"✅ GIF complete!")
      print(f"Downloaded to: {result.downloaded_paths}")
      print(f"Credits charged: {result.credits_charged}")
  else:
      print(f"❌ Job failed with status: {result.status}")
      if result.error:
          print(f"Error: {result.error.code}: {result.error.message}")
  ```

  ```javascript Node.js theme={null}
  import { Client } from "magic-hour";

  const client = new Client({ token: process.env.MAGIC_HOUR_API_KEY });

  const result = await client.v1.aiGifGenerator.generate(
    {
      style: {
        prompt: "Cute dancing cat, pixel art",
      },
      outputFormat: "gif",
      name: "GIF Generator image",
    },
    {
      waitForCompletion: true,
      downloadOutputs: true,
      downloadDirectory: ".",
    }
  );

  console.log(`Status: ${result.status}`);
  console.log(`Downloaded to: ${result.downloadedPaths}`);
  ```
</CodeGroup>

## Pricing

| Output         | Credits    |
| :------------- | :--------- |
| 1 animated GIF | 50 credits |

<Tip>
  **Try this in our Google Colab Cookbook:** [Run this API with sample
  code](https://colab.research.google.com/drive/1NTHL_lr_s-qBJ-mSecSXPzRLi9_V5JiU?usp=sharing). Just
  add your API key.
</Tip>

## API Reference

<Card title="AI GIF Generator API Reference" icon="webhook" href="/api-reference/image-projects/ai-gif-generator">
  View full API specification
</Card>

## Related Tools

<CardGroup cols={2}>
  <Card title="Animation" icon="film" href="/tools/video/animation">
    Create video animations with advanced effects
  </Card>

  <Card title="AI Meme Generator" icon="face-laugh" href="/tools/image/meme-generator">
    Generate memes with text and templates
  </Card>
</CardGroup>
