# ForLoop Media integration guide Generate images, transform stored images, read images as text, and synthesize speech through asynchronous, billable media jobs. - Base URL: `https://media.app.forloop.cc` - Console: `https://media.app.forloop.cc/console` - Contract version: `1.4.0` - Supported versions: `1.3.0, 1.4.0` - Machine-readable guide: `https://media.app.forloop.cc/llms.txt` ## Quickstart Create an app-subject connection to this service, then exchange the app credential for an assertion. ```bash curl -X POST https://media.app.forloop.cc/api/opencode/a2a/connections//assertion \ -H "x-api-token: $FLC_APP_CREDENTIAL" \ -H "content-type: application/json" \ -d '{"scopes":["media.jobs:write"],"contractVersion":"1.4.0"}' ``` The assertion is valid for **300 seconds**. Send it as `Authorization: Bearer ` on every `/v1` call. 1. Submit an image, vision, or speech job with POST /v1/images, /v1/vision, or /v1/speech. 2. Poll GET /v1/jobs/{id} until the job reaches a terminal status. 3. Read the stored asset through the returned signed URL or export endpoint. 4. Inspect GET /v1/usage for charged assets and wallet state. ## Authentication and tenancy The service trusts only a verified app assertion. It checks `iss`, `aud`, `sub=app:`, `appPublicId`, `env`, scopes, and the pinned `contractVersion`. - The payer is always `APP:` from the assertion; never accept a payer or app ID from the request body. - Resources are scoped to `(appPublicId, env)`. A foreign resource returns `404`, not `403`. - Writes require `Idempotency-Key`. Reuse the same key only for the same logical request. - Reuse the same assertion for a short logical workflow, but exchange a fresh one for a new workflow; do not cache it indefinitely. ## Scopes - `media.jobs:read` - `media.jobs:write` - `media.voices:write` ## API reference | Method | Path | Access | Success | Tool | Purpose | | --- | --- | --- | --- | --- | --- | | `POST` | `/v1/images` | write | 202 | Generate image | Create an image job from a natural-language prompt. Returns 202 immediately with a jobId; the provider call, moderation, object-storage write, and charge happen asynchronously. One request may ask for up to 4 images (n); each stored image is charged separately. Requires an Idempotency-Key header. | | `POST` | `/v1/speech` | write | 202 | Generate speech | Create a text-to-speech job. Returns 202 immediately with a jobId; synthesis, subtitle sidecar, object-storage write, and charge happen asynchronously. Text up to 10,000 characters is synthesized inline; longer text (up to 50,000 inline, or 1,000,000 via textFileId) requires asyncTask and is polled until the provider task completes. Billing is per 1,000 provider-reported characters. Requires an Idempotency-Key header. | | `POST` | `/v1/music` | write | 202 | Generate music | Create a music job. Returns 202 immediately with a jobId; synthesis, object-storage write, and charge happen asynchronously. Supports instrumental tracks from a prompt, lyrical songs from structured lyrics, and cover generation from audio this app already stored. One song per request, charged per stored song. Requires an Idempotency-Key header. | | `GET` | `/v1/jobs/{id}` | read | 200 | Get job | Read one job, including fresh short-lived signed URLs for every stored image. This is the 'load the image back' call: render assets[].url directly, and call again when a URL expires. | | `GET` | `/v1/jobs` | read | 200 | List jobs | Cursor-paginated list of the caller app's jobs in this environment, newest first. List responses never include signed URLs. | | `POST` | `/v1/jobs/{id}/cancel` | write | 202 | Cancel job | Cancel a job that is still queued. The reservation is released, so a canceled job is free. Requires an Idempotency-Key header. | | `POST` | `/v1/jobs/{id}/export` | write | 200 | Export job | Mint longer-lived download URLs (default 1 hour) so the app can copy the image bytes into its own storage before the 30-day retention window closes. Requires an Idempotency-Key header. | | `POST` | `/v1/jobs/{id}/retain` | write | 200 | Retain job | Extend retention by a number of days, or retain indefinitely with days=0, so the images are not deleted at expiresAt. Requires an Idempotency-Key header. | | `GET` | `/v1/jobs/{id}/assets/{index}/content` | read | 302 | Redirect to asset | Stable per-asset endpoint that 302-redirects to a freshly signed URL, so an app can use one URL in an without minting it first. | | `DELETE` | `/v1/jobs/{id}` | write | 204 | Delete job | Delete the stored images and the job record immediately. Requires an Idempotency-Key header. | | `GET` | `/v1/usage` | read | 200 | Get usage | Usage summary for a time window: job counts by status, images stored, stored bytes, charged FLC, and the app's live wallet balance and spend cap. | | `POST` | `/v1/voices` | write | 201 | Clone voice | Clone a voice from audio this app already stored, subject to an explicit consent attestation. Returns 201 with a voiceId usable as voiceId on POST /v1/speech. Cloning is biometric processing, so it requires the separate media.voices:write scope and is disabled by default. Requires an Idempotency-Key header. | | `GET` | `/v1/voices` | read | 200 | List voices | List this app's voices in the environment. Returns ids, kind, status and the consent attestor and timestamp; the attestation text and any audio are never returned. | | `GET` | `/v1/voices/{id}` | read | 200 | Get voice | Fetch one voice by id. | | `DELETE` | `/v1/voices/{id}` | write | 204 | Delete voice | Delete a cloned voice locally and ask the provider to delete its model. The local record is marked deleted first, so a provider failure cannot leave the caller believing a voice still exists. Requires an Idempotency-Key header. | | `POST` | `/v1/vision` | write | 202 | Image to text | Describe or answer questions about one or more stored images using DeepSeek vision. Returns 202 with a job; poll get_job until status is succeeded and read job.text. Each stored image is charged once (media.vision, 2 FLC/image); failed descriptions are free. | ### Generate image `POST /v1/images` · write · success 202 Create an image job from a natural-language prompt. Returns 202 immediately with a jobId; the provider call, moderation, object-storage write, and charge happen asynchronously. One request may ask for up to 4 images (n); each stored image is charged separately. Requires an Idempotency-Key header. **Example** ```http POST /v1/images Idempotency-Key: avatar-user-42-v1 Authorization: Bearer {"prompt":"A cat in a spacesuit, studio lighting","aspectRatio":"1:1"} 202 {"job":{"jobId":"job_6f1c...","status":"queued","params":{"model":"image-01","requestedCount":1,"aspectRatio":"1:1"},"assets":[],"billing":{"state":"reserved","quotedAmountFLC":50,"unitAmountFLC":50},"expiresAt":"2026-11-28T09:00:00.000Z"}} ``` **Output fields:** job ### Generate speech `POST /v1/speech` · write · success 202 Create a text-to-speech job. Returns 202 immediately with a jobId; synthesis, subtitle sidecar, object-storage write, and charge happen asynchronously. Text up to 10,000 characters is synthesized inline; longer text (up to 50,000 inline, or 1,000,000 via textFileId) requires asyncTask and is polled until the provider task completes. Billing is per 1,000 provider-reported characters. Requires an Idempotency-Key header. **Example** ```http POST /v1/speech Idempotency-Key: narration-ch3-v1 Authorization: Bearer {"text":"Welcome to ForLoop.","voiceId":"male-qn-qingse","format":"mp3"} 202 {"job":{"jobId":"job_9a2c...","modality":"speech","status":"queued","params":{"model":"speech-2.8-hd","requestedCount":1,"format":"mp3","sampleRate":32000},"assets":[],"billing":{"state":"reserved","quotedAmountFLC":2,"unitAmountFLC":2},"expiresAt":"2026-12-03T09:00:00.000Z"}} ``` **Output fields:** job ### Generate music `POST /v1/music` · write · success 202 Create a music job. Returns 202 immediately with a jobId; synthesis, object-storage write, and charge happen asynchronously. Supports instrumental tracks from a prompt, lyrical songs from structured lyrics, and cover generation from audio this app already stored. One song per request, charged per stored song. Requires an Idempotency-Key header. **Example** ```http POST /v1/music Idempotency-Key: lobby-theme-v1 Authorization: Bearer {"prompt":"uplifting synthwave, driving bass, 80s","isInstrumental":true} 202 {"job":{"jobId":"job_4d1e...","modality":"music","status":"queued","params":{"model":"music-3.0","requestedCount":1,"isInstrumental":true},"assets":[],"billing":{"state":"reserved","quotedAmountFLC":200,"unitAmountFLC":200},"expiresAt":"2026-12-03T09:00:00.000Z"}} ``` **Output fields:** job ### Get job `GET /v1/jobs/{id}` · read · success 200 Read one job, including fresh short-lived signed URLs for every stored image. This is the 'load the image back' call: render assets[].url directly, and call again when a URL expires. **Example** ```http GET /v1/jobs/job_6f1c... Authorization: Bearer 200 {"job":{"jobId":"job_6f1c...","status":"succeeded","assets":[{"index":0,"contentType":"image/png","bytes":812345,"width":1024,"height":1024,"url":"https://s3...","urlExpiresAt":"2026-10-29T10:15:00.000Z"}],"billing":{"state":"charged","chargedAmountFLC":50}}} ``` **Output fields:** job ### List jobs `GET /v1/jobs` · read · success 200 Cursor-paginated list of the caller app's jobs in this environment, newest first. List responses never include signed URLs. **Example** ```http GET /v1/jobs?status=succeeded&limit=20 200 {"jobs":[{"jobId":"job_6f1c...","status":"succeeded","assets":[{"index":0,"contentType":"image/png","bytes":812345}],"expiresAt":"2026-11-28T09:00:00.000Z"}],"nextCursor":"..."} ``` **Output fields:** jobs, nextCursor ### Cancel job `POST /v1/jobs/{id}/cancel` · write · success 202 Cancel a job that is still queued. The reservation is released, so a canceled job is free. Requires an Idempotency-Key header. **Example** ```http POST /v1/jobs/job_6f1c.../cancel Idempotency-Key: cancel-job_6f1c 202 {"job":{"jobId":"job_6f1c...","status":"canceled","billing":{"state":"released"}}} ``` **Output fields:** job ### Export job `POST /v1/jobs/{id}/export` · write · success 200 Mint longer-lived download URLs (default 1 hour) so the app can copy the image bytes into its own storage before the 30-day retention window closes. Requires an Idempotency-Key header. **Example** ```http POST /v1/jobs/job_6f1c.../export Idempotency-Key: export-job_6f1c 200 {"jobId":"job_6f1c...","assets":[{"index":0,"contentType":"image/png","bytes":812345,"url":"https://s3..."}],"urlExpiresAt":"2026-10-29T11:00:00.000Z","expiresAt":"2026-11-28T09:00:00.000Z"} ``` **Output fields:** jobId, assets, urlExpiresAt, expiresAt ### Retain job `POST /v1/jobs/{id}/retain` · write · success 200 Extend retention by a number of days, or retain indefinitely with days=0, so the images are not deleted at expiresAt. Requires an Idempotency-Key header. **Example** ```http POST /v1/jobs/job_6f1c.../retain Idempotency-Key: retain-job_6f1c {"days":90} 200 {"job":{"jobId":"job_6f1c...","expiresAt":"2027-01-27T09:00:00.000Z","retained":false}} ``` **Output fields:** job ### Redirect to asset `GET /v1/jobs/{id}/assets/{index}/content` · read · success 302 Stable per-asset endpoint that 302-redirects to a freshly signed URL, so an app can use one URL in an without minting it first. **Example** ```http GET /v1/jobs/job_6f1c.../assets/0/content 302 location: https://s3.ap-southeast-1.amazonaws.com/...?X-Amz-Signature=... ``` **Output fields:** ### Delete job `DELETE /v1/jobs/{id}` · write · success 204 Delete the stored images and the job record immediately. Requires an Idempotency-Key header. **Example** ```http DELETE /v1/jobs/job_6f1c... Idempotency-Key: delete-job_6f1c 204 ``` **Output fields:** ### Get usage `GET /v1/usage` · read · success 200 Usage summary for a time window: job counts by status, images stored, stored bytes, charged FLC, and the app's live wallet balance and spend cap. **Example** ```http GET /v1/usage?from=2026-10-01T00:00:00Z&to=2026-10-29T00:00:00Z 200 {"usage":{"total":12,"succeeded":11,"images":14,"storedBytes":9345211,"chargedFLC":700,"counts":{"succeeded":11,"content_filtered":1},"wallet":{"available":4300,"spent":700,"spendCap":10000,"currency":"FLC"}}} ``` **Output fields:** usage ### Clone voice `POST /v1/voices` · write · success 201 Clone a voice from audio this app already stored, subject to an explicit consent attestation. Returns 201 with a voiceId usable as voiceId on POST /v1/speech. Cloning is biometric processing, so it requires the separate media.voices:write scope and is disabled by default. Requires an Idempotency-Key header. **Example** ```http POST /v1/voices Idempotency-Key: clone-user-42-v1 Authorization: Bearer {"source":{"jobId":"job_9a2c...","index":0},"label":" narrator","consent":{"attested":true,"attestedBy":"user_42","statement":"I confirm the person whose voice is used has given informed consent for this voice to be cloned and used by this application."}} 201 {"voice":{"voiceId":"voice_7f3...","kind":"cloned","status":"active","consent":{"attested":true,"attestedBy":"user_42","attestedAt":"2026-11-03T09:00:00.000Z"},"expiresAt":"2026-11-10T09:00:00.000Z"}} ``` **Output fields:** voice ### List voices `GET /v1/voices` · read · success 200 List this app's voices in the environment. Returns ids, kind, status and the consent attestor and timestamp; the attestation text and any audio are never returned. **Example** ```http GET /v1/voices?limit=50 200 {"voices":[{"voiceId":"voice_7f3...","kind":"cloned","status":"active"}]} ``` **Output fields:** voices, nextCursor ### Get voice `GET /v1/voices/{id}` · read · success 200 Fetch one voice by id. **Example** ```http GET /v1/voices/voice_7f3... 200 {"voice":{"voiceId":"voice_7f3...","status":"active"}} ``` **Output fields:** voice ### Delete voice `DELETE /v1/voices/{id}` · write · success 204 Delete a cloned voice locally and ask the provider to delete its model. The local record is marked deleted first, so a provider failure cannot leave the caller believing a voice still exists. Requires an Idempotency-Key header. **Example** ```http DELETE /v1/voices/voice_7f3... Idempotency-Key: withdraw-consent-42 204 ``` **Output fields:** ### Image to text `POST /v1/vision` · write · success 202 Describe or answer questions about one or more stored images using DeepSeek vision. Returns 202 with a job; poll get_job until status is succeeded and read job.text. Each stored image is charged once (media.vision, 2 FLC/image); failed descriptions are free. **Example** ```http POST /v1/vision Idempotency-Key: alt-text-42 Authorization: Bearer {"images":[{"jobId":"job_6f1c...","index":0}],"prompt":"Describe this image in one sentence."} 202 {"job":{"jobId":"job_9a2c...","modality":"vision","status":"queued","params":{"model":"deepseek-flash","images":[{"jobId":"job_6f1c...","index":0}]},"assets":[],"billing":{"state":"reserved","quotedAmountFLC":2},"expiresAt":"2026-12-03T09:00:00.000Z"}} ``` **Output fields:** job ## Errors and retries | Code | Meaning | Retry? | | --- | --- | --- | | `invalid_assertion` / `expired` | The assertion is missing, invalid, or expired. | No; exchange a fresh assertion. | | `insufficient_scope` | The assertion does not carry a required scope. | No; update the connection grant. | | `env_mismatch` / `audience_mismatch` | Wrong platform environment or target. | No; fix the connection. | | `invalid_request` | The request body or parameters are invalid. | No. | | `not_found` | The resource is absent or belongs to another app. | No. | | `conflict` | Version, state, or idempotency conflict. | No; read the current state first. | | `quota_exceeded` / `rate_limited` | Per-app quota or rate limit reached. | Yes, after the indicated delay. | | `internal_error` / `provider_transport` | Transient platform or provider failure. | Yes, with backoff and the same idempotency key. | ## Billing undefined FLC per 1 unit (ceil). Payer: `APP:`. Failures are free. The service reserves before billable work and commits only after the success condition in its contract. A failed, filtered, or canceled unit is free. A successful unit that cannot settle is retried durably and is never silently released. ## Limits and retention - Generated assets are retained for 30 days by default; export before expiry. - Image generation costs 50 FLC per stored image; vision costs 2 FLC per stored image; speech costs 2 FLC per 1,000 characters. - Music and voice cloning are disabled unless the deployment explicitly enables them. - Use the `Idempotency-Key` header for every write. ## AI-agent checklist 1. Discover the target agent card and pin its exact contract version. 2. Exchange the app credential for a fresh assertion immediately before the call. 3. Use the generated client types; never hand-write a response type. 4. Send `Idempotency-Key` on every write and reuse it only for the same logical request. 5. Never infer the payer or app ID from a request body; use the verified assertion. 6. Treat 4xx errors as terminal unless the contract explicitly says otherwise; retry only transient 5xx/transport errors with backoff. 7. Read the returned job/delivery state before presenting success to a user. - Jobs are asynchronous: never treat a 202 as completed work. - A job can be partially successful; bill only the stored primary assets. - Signed asset URLs are bearer credentials and must not be logged or stored in docs.