# Batch-animate game assets with the API

> Animate a whole folder of game icons into Spine 4.2 exports with the Animate4Me REST API: a ready Python script, limits, prices and how to fit it into a build pipeline.

Page: https://animate4me.com/batch-animate-game-assets-api.html

When a game has dozens of icons, items or props, clicking through the app for each one is slow. The Animate4Me [REST API](https://animate4me.com/api.html) runs the same pipeline from a script: upload a picture, wait for the job, download the Spine 4.2 ZIP.

Below is a complete Python script that animates every PNG in a folder, plus the numbers you need to plan a batch.

[Read the API reference](https://animate4me.com/api.html) [Open the app](https://animate4me.com/app.html)

## How do I animate many game assets into Spine at once?

Animate4Me has a REST API that turns each picture in a folder into a Spine 4.2 ZIP from your own script or build pipeline.

**Best for:** studios and developers with a full icon or item set to animate, or a pipeline that adds new art often.

**Key advantages:**

- Same results and prices as the app.
- Bearer keys, JSON answers, one ZIP per job.
- Failed jobs return their tokens by themselves.
- Up to 500 new jobs per day per account.

**What you get:** one Spine 4.2 ZIP per picture (skeleton.json, skeleton.atlas, PNG page, README); 20 tokens per symbol or object.

## What you need

- The **Studio** plan ($59 a month for 1200 tokens) or **Pro** ($199 a month for 5000 tokens). The API is part of these plans.
- An API key from **My account > API keys**, kept in an environment variable `A4M_KEY`.
- Python 3 with the `requests` package.

## Plan the batch

- One symbol or object from an image costs **20 tokens**, so Studio's 1200 monthly tokens cover 60 animations and Pro's 5000 cover 250. Subscribers can add top-ups.
- Up to **2 jobs in progress** and **500 new jobs per day** per account; **60 requests per minute** per key and 120 per account.
- A symbols job usually takes under a minute.
- Check the balance first with `GET /api/v1/account`; it costs nothing.

## The script

It animates every PNG in `art/icons` with `idle` and `win`, keeps at most two jobs running, waits on `429` answers as the API asks, and saves each ZIP into `spine/`.

```
import os, sys, time, pathlib, requests

BASE = "https://animate4me.com"
HEAD = {"Authorization": "Bearer " + os.environ["A4M_KEY"]}
SRC, OUT = pathlib.Path("art/icons"), pathlib.Path("spine")
TEMPLATES = ["idle", "win"]          # one list per job: symbol or object templates
MAX_ACTIVE = 2                       # the account limit for jobs in progress

def call(method, path, **kw):
    while True:
        r = requests.request(method, BASE + path, headers=HEAD, timeout=120, **kw)
        if r.status_code == 429 and r.json().get("error") in ("rate_limited", "too_many_active"):
            time.sleep(int(r.headers.get("Retry-After", 10)))   # wait and retry
            continue
        return r                     # anything else, including 429 daily_limit, goes back to the caller

acc = call("GET", "/api/v1/account").json()
todo = sorted(SRC.glob("*.png"))
cost = acc["prices"]["symbols_from_image"] * len(todo)
print(f"{len(todo)} pictures, {cost} tokens, balance {acc['tokens']}")
if cost > acc["tokens"]:
    sys.exit("not enough tokens")

OUT.mkdir(exist_ok=True)
running = {}                         # job_id -> picture
while todo or running:
    while todo and len(running) < MAX_ACTIVE:
        pic = todo.pop(0)
        data = [("category", "symbols"), ("name", pic.stem)] + [("templates", t) for t in TEMPLATES]
        with open(pic, "rb") as f:
            r = call("POST", "/api/v1/jobs", data=data, files={"image": f})
        if r.status_code != 201:     # refused: nothing was charged
            print("refused", pic.name, r.json().get("message"))
            if r.json().get("error") in ("daily_limit", "insufficient_tokens"):
                todo.clear()         # stop submitting; the running jobs still finish
            continue
        running[r.json()["job_id"]] = pic
    time.sleep(4)
    for job_id, pic in list(running.items()):
        job = call("GET", f"/api/v1/jobs/{job_id}").json()
        if job["status"] == "done":
            zip_ = call("GET", f"/api/v1/jobs/{job_id}/zip")
            (OUT / f"{pic.stem}_spine42.zip").write_bytes(zip_.content)
            print("saved", pic.stem)
            del running[job_id]
        elif job["status"] == "failed":                          # tokens come back by themselves
            print("failed", pic.name, job.get("error"))
            del running[job_id]
```

For props and pickups, set `TEMPLATES` to the object list, for example `["appear", "open", "collect"]`. Mixing symbol and object templates in one job is refused with `400 mixed_templates`, without a charge.

## After the batch

- **Fix one result in words.** `POST /api/v1/jobs/{job_id}/edit` with `{"text": "make the win jump higher"}` makes a new version (5 tokens); every version stays downloadable with `?version=n`.
- **Moving parts.** `POST /api/v1/jobs/{job_id}/split` builds a new animation where the parts move on their own (50 tokens).
- **Load them in your engine.** See the guides for [Unity](https://animate4me.com/spine-animation-for-unity.html), [Godot](https://animate4me.com/spine-animation-for-godot.html), [Phaser](https://animate4me.com/spine-animation-for-phaser.html) and [PixiJS](https://animate4me.com/spine-animation-for-pixijs.html).

## Errors you may see

- `402 insufficient_tokens`: nothing was charged; top up or wait for next month's tokens.
- `413/422 bad_image`: the image was rejected (the message says why); nothing was charged.
- `400 content_blocked`: blocked by our content policy; nothing was charged.
- `429 daily_limit`: 500 new jobs per day reached; continue tomorrow (UTC).
- `403 api_not_in_plan`: the account is not on Studio or Pro.

The full list is on the [API page](https://animate4me.com/api.html).

## Questions and answers

### How many animations can I make per month?

At 20 tokens per symbol or object from an image, Studio (1200 tokens a month) covers 60 and Pro (5000 tokens a month) covers 250. Top-ups add more.

### How many jobs can run at once?

Up to 2 jobs in progress and 500 new jobs per day per account. The script above keeps two running.

### What happens if a job fails?

Its tokens are returned automatically, and the job status says why.

### Is the API on the Indie plan?

No. The REST API and the MCP server are part of the Studio and Pro plans.

## Related

- [Spine animation from your AI assistant (MCP)](https://animate4me.com/spine-animation-with-ai-assistant-mcp.html)
- [API reference](https://animate4me.com/api.html)
- [Pricing](https://animate4me.com/pricing.html)
- [How to animate game icons in Spine](https://animate4me.com/how-to-animate-game-icons-in-spine.html)
- [Animate4Me home](https://animate4me.com/)

## Animate your whole asset set.

[Read the API reference](https://animate4me.com/api.html)

[Plans and token prices](https://animate4me.com/pricing.html)

---

Animate4Me: https://animate4me.com/ · Contact: contact@animate4me.com · X: https://x.com/Animate4Me · All pages for AI assistants: https://animate4me.com/llms.txt

Spine is a trademark of Esoteric Software. Animate4Me is not affiliated.
