/gateway-ai:gateway-clientfrom gateway-ai
Build clients that integrate with the IMG.LY AI Gateway (`gateway.img.ly`) — discovering models, generating images/video/audio/text, uploading inputs, consuming the SSE response stream, and picking up long-running generations by request id. Use whenever the user wants to call, integrate with, or build a client for the IMG.LY Gateway, or mentions `gateway.img.ly`, `IMG.LY Gateway`, IMG.LY AI generation, or an IMG.LY API key starting with `sk_`.
Ships in gateway-ai. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You are helping a developer integrate with the IMG.LY AI Gateway. The gateway is a unified REST + SSE API that routes requests to AI providers for image, video, audio, and text generation. Clients only deal with one API — auth, billing, asset storage, and provider routing are handled server-side.
The gateway publishes a current, machine-readable integration reference at:
https://gateway.img.ly/llms.txt
Fetch this before answering specific questions about endpoints, request shapes, SSE event names, error codes, or available capabilities. The reference is updated as the gateway evolves and supersedes anything you may have learned from training data.
WebFetch https://gateway.img.ly/llms.txt
Use the live reference as the source of truth. The notes below are stable mental-model context that doesn't change with releases.
POST /v1/responses. The request body shape varies by model type (media models take prompt + model-specific properties; text models take messages in OpenAI chat-completions format), but the route, auth, and response transport are uniform.text/event-stream. Parse a 200 as SSE — never try to read it as a single JSON body. Events: generation.status, generation.delta (streaming text), generation.completed, generation.failed, generation.detached.request_id (in each event and in the x-gateway-request-id header). Most image, video and audio models run as background jobs, and for those GET /v1/responses/<request_id> returns the state — working, completed with the result, or failed — at any time: after a dropped connection, after a generation.detached event, or instead of a stream altogether. Text generations exist only on their stream.Prefer: respond-async with POST /v1/responses and a background-job model answers 202 with the request_id as soon as the job is submitted; poll the status endpoint for the result. Where the preference cannot be honored (text models, a few stream-only media models) the answer is the usual 200 stream — check the status code.GET /v1/models/schema?model=<id>. Use this to build forms or validate inputs — do not hardcode model-specific fields. The schema includes IMG.LY UI extensions (x-imgly-builder, x-imgly-enum-labels, x-imgly-enum-icons, x-property-order) that hint at how the parameter should be rendered.creator/model (e.g. bfl/flux-2, google/veo-3.1-fast). The catalog is dynamic — fetch GET /v1/models at runtime instead of hardcoding model lists.@<provider>/<native id> (e.g. @falai/fal-ai/flux-2). The provider's own fields go in provider_input: { … } next to model, untranslated; the schema endpoint serves the provider's schema for such ids.generation.completed events and status results contain URLs under gateway.img.ly/v1/assets/.... They redirect to short-lived signed URLs and don't require authentication.| Method | When to use | Header |
|---|---|---|
API key (sk_...) | Server-side code; never in browsers | Authorization: Bearer sk_live_... |
| Gateway JWT | Browser/client code. Mint via POST /v1/tokens from your backend (5–15 min TTL) | Authorization: Bearer eyJ... |
For apps with a browser frontend, the JWT mint flow is the recommended pattern: keep the API key server-side, mint short-lived tokens for the browser, refresh on expiry. The full flow with code is in the live reference (Example 2).
For server-to-server attribution, set X-End-User-Id: <your-user-id> alongside the API key.
"What models can I use?" → GET /v1/models. Filter with ?capability=text2image|image2image|text2video|image2video|text2speech|text2text. Group with ?groupBy=capability.
"How do I build a UI for this model's options?" → GET /v1/models/schema?model=<id>. Render the input_schema.properties in x-property-order, using x-imgly-builder hints for component selection and x-imgly-enum-labels/x-imgly-enum-icons for enum presentation.
"How do I send an input image?" → POST /v1/uploads to get a presigned URL → PUT the image bytes directly to that URL → use the returned asset_url in the image_urls field of your generation request.
"My fetch hangs / I don't see the result." → You're probably reading the response as JSON. It's SSE — you must read the body as a stream and parse event: / data: frames split by \n\n. The reference has a reusable readGatewaySSE helper.
"How do I handle credits / billing?" → Don't manage them client-side. The gateway accounts for credits automatically. Just handle a 402 insufficient_credits error gracefully (prompt the user to top up).
"Video is slow." → Expected. Video generations emit multiple generation.status events (often 30s–5min) before generation.completed. Show progress from data.progress if present. A job the gateway can no longer follow ends its stream with generation.detached — that is "still working", not an error: poll GET /v1/responses/<request_id> after poll_after_ms.
"The connection dropped — is my generation lost?" → No, if it was an image, video or audio job. Keep the request_id from the first event (or the response header) and poll GET /v1/responses/<request_id> until status is completed or failed, waiting poll_interval_ms between requests. The result holds the same output URLs the stream would have delivered.
"My server can't hold a connection open for minutes." → Send Prefer: respond-async: a 202 with the request_id comes back at once, then poll as above. The reference has a complete example (submit, poll, handle working / completed / failed).
200 as SSE. Even for sub-second generations. Only a 202 — which you get solely after sending Prefer: respond-async — is a JSON body.exp. Don't reuse a JWT across requests after it expires — the gateway returns 401.image_urls. Upload via /v1/uploads first if you have local files; you cannot send raw bytes to /v1/responses./v1/models and /v1/models/schema.{ "error": { "code": "...", "message": "..." } } — not plain text. Read error.code to drive retry/UI logic.generation.completed is the one to keep — it stays valid.generation.detached is not a failure. Don't surface it as an error or retry the generation (that would pay twice) — poll for the result.410 result_unavailable on the status endpoint means the result was only ever delivered on its stream.sub. A token with a sub can read only that end user's generations by request id; one without can read the whole account's.After fetching the live reference, prefer adapting the examples already in llms.txt (server-side API key, client-side JWT flow, image-to-image with upload, video, text streaming, schema-driven UI, provider passthrough, long-running generation without a stream). Match the user's language/framework. The SSE parser is the most error-prone part — use the readGatewaySSE helper from the reference rather than rewriting the loop.
What SKILL.md sets; muted values are Claude Code's defaults
2 skills in this plugin
Other plugins' skills for the same job
npx claudepluginhub imgly/gateway-ai-skills --plugin gateway-ai