Skip to content
Generate images and video
Developer documentation/Tools and integrations

Generate images and video

Enable Rebyte-hosted media tools on an Agent and download the results from its Session.

On this pageEnable the toolsSet limits in the declarationRead the resultBilling

The Agents API can generate images and video with Rebyte-hosted tools. Enable each tool in agent.tools and set agent.budget.max_credits. The tools run on Rebyte's server and work in a Session with environment.type: "none".

Enable the tools

Send POST /v1/agents/sessions to https://api.rebyte.ai with your organization API key and the OpenAI-Beta: agents=v1 header. This example enables one image model and the video tool. Omit either tool to leave it disabled.

json
{
  "agent": {
    "model": "gpt-6-luna",
    "budget": { "max_credits": 150 },
    "tools": [
      { "type": "image_generation", "model": "gpt-image-2.6-flare" },
      { "type": "video_generation" }
    ]
  },
  "environment": { "type": "none" },
  "input": "Generate an image of a red ceramic mug on a white table."
}

The same tool declarations work on a saved Agent. The caller chooses the image model in configuration. The Agent passes a text prompt to the tool.

ToolMedia modelOutputMaximum reservation per call
image_generationbytedance-seed/seedream-5-5 via OpenRouterSquare 1K PNG4 credits
image_generationgpt-image-2.6-flareSquare 1024px PNG, low quality9 credits
image_generationgemini-3.1-flash-lite-imageSquare 1K JPEG8 credits
video_generationbytedance/seedance-2.5-flash via OpenRouterSilent 16:9 MP462 credits for the 4-second 480p default

For video, ask for a duration of 4–10 seconds and either 480p or 720p. Requests above 10 seconds fail before Rebyte reserves credits or calls the provider. The reservation increases with duration and resolution.

Set limits in the declaration

Optional fields on each tool fix limits in configuration, so they do not depend on the prompt or on what the model decides:

FieldToolsValuesEffect
max_calls_per_turnimage_generation, video_generationInteger 1–100Maximum calls of this tool in one Turn. Later calls in the same Turn fail before Rebyte reserves credits or calls the provider.
resolutionvideo_generation480p or 720pEvery video uses this resolution. The model cannot choose another one.
max_duration_secondsvideo_generationInteger 4–10Longest video the model can request.

This declaration allows at most two images and one 480p video of up to 10 seconds per Turn:

json
{
  "tools": [
    { "type": "image_generation", "model": "bytedance-seed/seedream-5-5", "max_calls_per_turn": 2 },
    { "type": "video_generation", "resolution": "480p", "max_duration_seconds": 10, "max_calls_per_turn": 1 }
  ]
}

A call over max_calls_per_turn returns a tool output with an error that names the limit, and the Agent can tell the user. Failed calls do not count toward the limit. The next Turn starts a new count. With the limits set, the media charge of one Turn is at most max_calls_per_turn times the tool's maximum reservation: 8 credits for two Seedream images, and 155 credits for one 10-second 480p video.

Read the result

Find the successful function_call_output in the Session's Items or event stream. Its output is a JSON string with id, model, content_type, size_bytes, credits_used, and download_path.

Fetch download_path on https://api.rebyte.ai with the organization API key or a client secret for this Session. From the browser, keep the secret in memory and send it in the Authorization header along with OpenAI-Beta: agents=v1.

javascript
const result = JSON.parse(item.output);
const response = await fetch(`https://api.rebyte.ai${result.download_path}`, {
  headers: {
    Authorization: `Bearer ${clientSecret}`,
    'OpenAI-Beta': 'agents=v1',
  },
  credentials: 'omit',
});
if (!response.ok) throw new Error(`Download failed (${response.status})`);
const media = await response.blob();

Billing

The Session budget covers model calls and media tools. Rebyte checks the organization balance, the Session budget and max_calls_per_turn before it submits a media call. After a successful result, it converts the measured supplier cost at 200 credits per US dollar, rounds up to whole credits, and caps the charge at the reservation. The output reports the actual charge. Failed generations release their reservations. If the supplier does not report enough pricing data, Rebyte returns the completed media with a zero charge.

Each media debit appears in the organization credit history and counts toward the API key that started the Turn or issued its client secret. Model calls keep their own ledger entries. When you retry an event submission, reuse its Idempotency-Key and body to avoid starting a second Turn.