<!-- https://bobabanana.com/docs/api/agents/ · Give any LLM agent image, video, voice and sound generation: copy-paste tool definitions, OpenAPI, llms.txt and a long-poll loop. -->

# BobaBanana for AI agents: tools, OpenAPI and llms.txt

**AI agents can call the BobaBanana API as a tool to create images, videos, speech and sound effects from references, then wait for the result with a single long-poll call.** The API was designed for agents: predictable JSON, string-or-object inputs, URL inputs, idempotency keys, and error messages that say how to fix the request.

## Machine-readable resources for agents

| Resource | URL | Use |
|---|---|---|
| OpenAPI 3.1 spec | `https://bobabanana.com/docs/openapi.json` | Code generators, OpenAPI tool loaders, custom assistant actions |
| Live OpenAPI | `https://bobabanana.com/api/v1/openapi.json` | Always matches the running API |
| llms.txt | `https://bobabanana.com/docs/llms.txt` | Short index of the docs for LLMs |
| llms-full.txt | `https://bobabanana.com/docs/llms-full.txt` | All docs in one Markdown file |
| Markdown pages | Add `index.md` to any docs URL, e.g. `/docs/api/videos/index.md` | Clean text for retrieval |

## Why the BobaBanana API is agent-friendly

1. **One call to wait:** `GET /v1/jobs/{id}?wait=30` returns when the job is done.
2. **URLs everywhere:** inputs accept `https://` URLs, and outputs are signed URLs that need no key, so agents can chain jobs.
3. **Strings or objects:** `"reference_images": ["https://..."]` works as well as full objects.
4. **Safe retries:** the `Idempotency-Key` header prevents duplicate jobs.
5. **Actionable errors:** every error has a `code`, a human-readable `message` and the offending `param`.

## Tool definitions (JSON Schema)

These definitions use the `name` / `description` / `input_schema` tool format that tool-use LLM APIs accept; for a function-calling API that expects `parameters`, put the same schema under `parameters`.

```json
[
  {
    "name": "bobabanana_generate_image",
    "description": "Generate an image with BobaBanana. Use reference_images (https URLs with labels) or library @handles to keep characters, products and places consistent. Returns a job; call bobabanana_wait_for_job with its id.",
    "input_schema": {
      "type": "object",
      "properties": {
        "prompt": {"type": "string", "description": "What to create"},
        "reference_images": {"type": "array", "items": {"type": "object", "properties": {"url": {"type": "string"}, "label": {"type": "string"}}, "required": ["url"]}},
        "assets": {"type": "array", "items": {"type": "string"}, "description": "Library handles like @maya"},
        "aspect_ratio": {"type": "string", "enum": ["16:9", "9:16", "1:1", "4:3", "3:4"]}
      },
      "required": ["prompt"]
    }
  },
  {
    "name": "bobabanana_generate_video",
    "description": "Generate a video. Give image (a start frame URL) or prompt (+ references) to generate the first frame; optional last_frame to end on a picture. Or give motion_video (a 1-15 s clip whose movement is copied onto image) or extend_video (a clip of up to 15 s to continue from its last frame). Length: 2-10 s at 720p, 3-15 s at 1080p and 2160p (16:9 or 9:16); a motion transfer is as long as its clip. Optional at 720p: voice ('@handle') with script for a lip-synced talking character. Optional sound_effect (not with motion_video).",
    "input_schema": {
      "type": "object",
      "properties": {
        "image": {"type": "string", "description": "https URL of the start frame (or the subject for motion_video)"},
        "prompt": {"type": "string"},
        "reference_images": {"type": "array", "items": {"type": "object", "properties": {"url": {"type": "string"}, "label": {"type": "string"}}, "required": ["url"]}},
        "last_frame": {"type": "string", "description": "https URL of the picture the video ends on"},
        "motion_video": {"type": "string", "description": "https URL of an mp4 or mov clip, 1-15 s, whose movement is copied"},
        "extend_video": {"type": "string", "description": "https URL of an mp4, mov or webm clip of up to 15 s to continue"},
        "motion": {"type": "string", "description": "Camera and subject movement"},
        "duration_seconds": {"type": "number", "minimum": 2, "maximum": 15, "description": "2-10 s at 720p; 3-15 s at 1080p and 2160p (10 s at most with last_frame)"},
        "resolution": {"type": "string", "enum": ["720p", "1080p", "2160p"], "description": "720p is standard; 1080p and 2160p need 16:9 or 9:16 and take no voice or audio"},
        "aspect_ratio": {"type": "string", "enum": ["16:9", "9:16", "1:1", "4:3", "3:4"]},
        "voice": {"type": "string", "description": "Saved voice @handle (720p only)"},
        "script": {"type": "string", "description": "Words the character says"}
      }
    }
  },
  {
    "name": "bobabanana_wait_for_job",
    "description": "Wait up to 30 seconds for a BobaBanana job. Call again while status is queued or running. On succeeded, output contains url fields.",
    "input_schema": {"type": "object", "properties": {"job_id": {"type": "string"}}, "required": ["job_id"]}
  }
]
```

## Executing the tools

```python
import os, requests

API = "https://bobabanana.com/api/v1"
H = {"Authorization": f"Bearer {os.environ['BOBABANANA_API_KEY']}"}

def run_tool(name: str, args: dict) -> dict:
    if name == "bobabanana_generate_image":
        return requests.post(f"{API}/images", headers=H, json=args, timeout=60).json()
    if name == "bobabanana_generate_video":
        return requests.post(f"{API}/videos", headers=H, json=args, timeout=60).json()
    if name == "bobabanana_wait_for_job":
        return requests.get(f"{API}/jobs/{args['job_id']}", headers=H, params={"wait": 30}, timeout=45).json()
    raise ValueError(name)
```

Return the JSON to the model as the tool result. The model sees `status`, `eta_seconds` and, when done, `output.*.url`.

## A system prompt snippet for agents

```text
You can create media with BobaBanana tools. Jobs are asynchronous: after a generate call,
call bobabanana_wait_for_job with the returned id until status is succeeded, failed or canceled.
Videos take several minutes; tell the user the eta_seconds while waiting.
To keep a subject consistent, pass the same reference_images (with labels) or @handles every time.
To animate a picture you generated, pass its output.image.url as the video's image.
```

## Agent workflow recipes

1. **Storyboard to video:** generate 3 to 6 images with the same references, then animate each with `/v1/videos` using `image`.
2. **Product ad:** product photo as reference → lifestyle image → 6 s video with a `sound_effect`.
3. **Talking spokesperson:** portrait + saved `@voice` + script → lip-synced 9:16 clip.
4. **Podcast promo:** `/v1/speech` for the line, then `/v1/videos` with that speech URL as `audio`.

## Frequently asked questions

### Can a custom chat assistant use the BobaBanana API?
Yes. If it supports OpenAPI actions, import `https://bobabanana.com/docs/openapi.json` as an action and set Bearer authentication with your key.

### Can an LLM agent with tool use call the BobaBanana API?
Yes. Give it the tool definitions above, and run the calls in your code.

### Is there an MCP server?
Not yet. The tool definitions above wrap the REST API in the meantime.

### How should an agent handle errors?
Read `error.message` and `error.param`, fix the request, and retry. For `429` and `503`, wait for the `Retry-After` header.
