Build a LangChain tool that generates video: wrapping the RelayDance API for agents
To build a LangChain tool that generates video, wrap the RelayDance API as a custom LangChain tool that submits a POST to /v1/video/generations, polls GET /v1/video/generations/{task_id} until the status is succeeded or failed, then returns the video URL to your agent. Because RelayDance is OpenAI-compatible, set the base URL to https://relaydance.com/v1 and authenticate with a Bearer API key created in the console.
How to wrap the RelayDance API as a LangChain tool
Define a LangChain tool that accepts a prompt and duration, then calls the RelayDance video endpoint. According to the official relaydance.com/docs, 「Set base_url to https://relaydance.com/v1 and keep your OpenAI SDK」. Follow these steps:
- Create an API key at the RelayDance console and store it as an environment variable.
- Set
base_urltohttps://relaydance.com/v1. - In the tool function, POST to
/v1/video/generationswith model, prompt, and seconds (clips up to 15 seconds). - Add optional metadata: ratio, resolution, generate_audio, callback_url, and content[].
- Return the task_id to the polling step.
Register the function with LangChain's tool decorator so the agent can invoke it during reasoning. See relaydance.com/models for live rates.
How to poll for the result or use webhooks
Poll the task status endpoint until the job completes, or configure a callback for asynchronous delivery. After submitting the task, call GET /v1/video/generations/{task_id} on an interval until status is succeeded or failed; the response contains the video URL. For webhook mode, set metadata.callback_url and RelayDance POSTs the final state to your server, which suits long-running agents that should not block on polling. Reference media are passed in metadata.content[] and cited in the prompt as @image1 to @imageN. A single request supports up to 9 reference images, 3 reference videos, and 3 audio tracks. Your LangChain tool should surface the returned URL as the observation for the agent.
How RelayDance billing affects agent design
RelayDance uses pay-as-you-go pricing per generated video, so your tool only incurs cost on successful generations. According to the official relaydance.com docs, 「Failed or errored requests are never billed」, which means agents that retry after transient errors do not accumulate charges for those failures. Current per-model rates from relaydance.com/models include Seedance 2.0 at about $0.190 per second for 720p and about $0.470 per second for 1080p, Seedance Fast at about $0.152 per second, and Seedance native 4K at about $4.90 per 5-second clip. For image generation via /v1/images/generations, gpt-image-2 output is free and only input is billed, with image-to-image from about CNY 0.035.
Comparison of RelayDance video options for agents
Select a model tier based on the resolution and cost your agent workflow requires.
| Option | Price | Source |
|---|---|---|
| Seedance 2.0 720p | about $0.190 / second | relaydance.com/models |
| Seedance 2.0 1080p | about $0.470 / second | relaydance.com/models |
| Seedance Fast | about $0.152 / second | relaydance.com/models |
| Seedance native 4K | about $4.90 per 5-second clip | relaydance.com/models |
Authentication uses Authorization: Bearer YOUR_API_KEY, and payments are accepted via USDT and Stripe card. Because access is OpenAI-compatible, no BytePlus enterprise account or KYC is required.
FAQ
Do I pay for failed video generations in my agent? No. Billing is pay-as-you-go per generated video, and failed or errored requests are never billed, so retries after errors do not add cost.
Which endpoint does the LangChain tool call? Submit tasks with POST /v1/video/generations, then poll GET /v1/video/generations/{task_id} until the status is succeeded or failed.
How do I add reference images to the prompt? Place them in metadata.content[] and cite them in the prompt as @image1 to @imageN, with up to 9 reference images per request.
According to the official relaydance.com docs: "Failed or errored requests are never billed"
According to the official relaydance.com/docs docs: "Set base_url to https://relaydance.com/v1 and keep your OpenAI SDK"
Key facts and figures
| Item | Value | Source |
|---|---|---|
| Seedance 2.0 720p price | about $0.190 / second | relaydance.com/models |
| Seedance 2.0 1080p price | about $0.470 / second | relaydance.com/models |
| Seedance Fast price | about $0.152 / second | relaydance.com/models |
| Seedance native 4K price | about $4.90 per 5-second clip | relaydance.com/models |
| gpt-image-2 image billing | image output is free, only input is billed; image-to-image from about CNY 0.035; 4K and 1K output cost the same | relaydance.com/models |
| API protocol | OpenAI-compatible; set base_url to https://relaydance.com/v1 | relaydance.com/docs |
| Failed requests | failed or errored requests are never billed | relaydance.com/docs |
Data verified 2026-06-29; live prices are on the official /models page.