# Rightcode Image

> Configure a Right Code API key, generate or edit images through Right Code's asynchronous draw API, save original image files locally, and present them in the active AI agent. Use in Codex, Claude Code, or WorkBuddy when the user asks to set up or check Right Code authentication, or explicitly requests Right Code, rightapi.ai, right.codes, nano-banana, gpt-image through Right Code, or the Right Code draw endpoint; do not use when the user asks for the host agent's built-in image generator or another provider.

- Skill: `yfpgle-glitch/rightcode-image` (Agent Skill, multi-file: 5 files)
- Install (CLI): `npx skillmds@latest add yfpgle-glitch/rightcode-image`
- Raw SKILL.md: https://api.skillmd.com/api/skills/yfpgle-glitch/rightcode-image/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: yfpgle-glitch (https://skillmd.com/u/yfpgle-glitch)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/yfpgle-glitch/rightcode-image

---


# Right Code Image

Use the bundled client for the complete submit, poll, decode, download, and checkpoint flow. Do not rebuild the API sequence with ad-hoc commands.

Choose an available Python 3 launcher for the bundled scripts. Prefer `python3`; use `python` when it points to Python 3. The examples below use `python3`.

Default to model `gpt-image-2`, aspect ratio `16:9`, and resolution `1K` unless the user explicitly requests different values.

## Configure the API key

When the user asks to configure or check Right Code authentication:

1. If they do not have an account or API key, direct them to `https://www.rightapi.ai/register?aff=9ec111f0`. If they need creation instructions, also provide `https://docs.rightapi.ai/docs/rc_quick_start/apikey.html`; the documented path is Right Code dashboard → Token Management → Create Key.
2. Do not ask the user to paste the API key into the conversation. Run `python3 scripts/configure_api_key.py`. On macOS and Windows this opens a local hidden-input dialog; in another interactive terminal it uses a hidden prompt.
3. After configuration, run `python3 scripts/configure_api_key.py --check`. Report only the status and saved path. Never print, repeat, log, or embed the key in a command.
4. Do not make a paid image request merely to verify configuration. Explain that the first real generation is the paid verification step.

## Workflow

1. Verify internally that the current request explicitly asks to generate or edit an image and selects Right Code either by name or through an active router whose documented default is Right Code. The user does not need to say "paid", mention a price, or send a second confirmation. One request authorizes the requested output count and up to three total submit attempts per intended output when recovery is impossible; do not reuse that authorization for later requests or ask again between authorized recovery attempts.
   - A retry or resume for the same intended output is part of that output's authorization and does not increase the requested output count.
   - Report the provider, output count, and task count as a non-blocking progress update, then continue without asking for approval. Stop only for an actual platform-enforced approval, an authentication challenge, an unexpected cost increase, or a materially ambiguous request.
2. Read the API key from `RIGHT_CODES_API_KEY` or `~/.config/right-code/api_key`. Never ask the user to paste the key into chat, print it, or embed it in this Skill.
3. Run `python3 scripts/generate_image.py --help` when options are unclear.
4. Invoke the script once. Pass each reference image with a separate `--reference` argument. When `--output-dir` is omitted, the client must find a project root and save into the shared project-local image layout below. If no project root exists, it stops and asks for an explicit `--output-dir`; never fall back to Downloads, Desktop, or Codex internal state.
   - For multiple output images, pass `--count N`. The client must run `N` independent single-image tasks sequentially; never send provider field `n` greater than `1`.
   - Let the client derive a readable filename from the prompt. If the user gives a specific title, pass it with `--filename "title"`; omit the extension because the client detects the actual image format.
5. Read the final JSON from stdout. Present every absolute path in `files` and the matching Markdown prompt path using the host agent's supported artifact or Markdown features. Prefer an inline image plus a clickable local file link; if inline local images are unsupported, provide the saved file path and use the host's preview capability.
6. If the request fails, diagnose the exact `submit`, `poll`, or `download` stage. Prefer resuming a checkpointed task, reconnecting, polling again, or downloading again because those paths do not create another paid task. Automatically recover with bounded backoff and do not pause for progress confirmation. If no task can be recovered, use the authorization from step 1 for at most three total submit attempts. Only after three failed attempts, an unexpected cost increase, an authentication challenge, or a materially ambiguous request, report the evidence once and ask the user to intervene. Never ask for a new confirmation merely because a same-output retry is the next recovery step.

## Recover an existing task

When submission succeeded but polling stopped because of a transient network error, resume the saved task instead of running the generation command again:

```bash
python3 scripts/generate_image.py \
  --resume-task-id task_example
```

Resume mode only sends authenticated `GET` requests to the existing task and never submits a new paid task. Its checkpoint is stored under `output/images/.tasks/rightcode/`, apart from browseable images. Polling retries transient network errors with bounded exponential backoff. Transport-level retries inside one task do not count as new paid attempts. Use `--poll-retries N` to change that limit. Never combine resume mode with `--prompt`, `--reference`, or a `--count` other than 1.

## Project-local output layout

The default layout keeps browseable images, readable prompts, and task recovery records separate:

```text
<project>/output/images/
  YYYY-MM-DD/YYYYMMDD-HHMMSS-NNN-content.png
  .prompts/YYYY-MM-DD/YYYYMMDD-HHMMSS-NNN-content.md
  .tasks/rightcode/right-code-task-<task-id>.json
```

Project discovery prefers the nearest Git or Mercurial repository root over nested package markers, so running from `code/` still uses the repository root. Without a repository marker, the nearest project marker is used. Resume mode also searches the old `generated_images/.tasks/rightcode/` location between the current directory and project root, copying a matching checkpoint into the new layout without submitting a task. Existing artifacts are never automatically deleted.

Every saved image gets a same-stem Markdown prompt file with provider, model, size, operation, timestamp, and full prompt; secrets and temporary URLs are excluded. `output/images/.gitignore` ignores all generated artifacts. An explicit `--output-dir` remains available for a deliberate exception and uses hidden `.prompts` and `.tasks` sidecars there.

## Example

```bash
python3 scripts/generate_image.py \
  --prompt "一只戴着太空头盔的橘猫，电影级光影"
```

For an edit, append `--reference /absolute/path/reference.png`.

For three independent output images, append `--count 3`. This creates three paid tasks. Later tasks continue even if one task fails, and the final JSON reports `completed`, `failed`, `files`, and per-task details. Recover failed tasks under the three-attempt policy above instead of stopping after each failure.

## Protocol Requirements

- Keep `"async": true` in every submission.
- Keep provider field `"n": 1`. Right Code accepted larger values in testing but returned only one image, so generate multiple outputs as separate sequential tasks.
- Submit to `https://www.rightapi.ai/draw/v1/images/generations`.
- Poll the site-level `https://www.rightapi.ai/v1/tasks/{task_id}` endpoint without a `/draw` prefix.
- Treat a response containing an image URL, `b64_json`, or Gemini inline image as completed even when `status` is absent.
- Preserve the checkpoint written immediately after submission so a task remains traceable after polling errors.
- Download the original bytes locally before displaying them. Do not rely on a temporary remote URL as the final result.

