Agent generates pictures and videos
Let the agent choose the interface, limit the cost, submit the task and save the results.
Programming Agents can write and execute image or video API requests, but should not leave all media tasks to the chat model to freely guess the parameters. Use build actions as controlled tools and save recoverable task states.
Step one: Prepare special tools
Create an independent Key for the Agent, open only the required models and set the available quota. The key is read by the server or the local security environment and is not written to prompt words, tool results or code repositories. The tool input parameters clearly distinguish image generation, image editing, video creation and video query.
Step 2: Run through the image independently first
Press Image Generation to verify POST /v1/images/generations. The tool returns a file path or a controlled result URL without stuffing large chunks of Base64 back into the chat context. For editing tasks, press Image Edit to import materials; the local path cannot be used as an upstream readable URL.
Step 3: Split the video into creation and query
- Create a tool call
POST /v1/videosand save the gateway task ID in the response. - Persistence of task ID, model, creation time and business task number.
- The query tool calls
GET /v1/videos/{id}and waits for non-final tasks. - After success, read the content endpoint and save the file, verify MIME, size and playability.
- Return a status summary and result location to the Agent.
For specific commands, see Video Generation. Not every model can use a unified video protocol, and tools should fix proven protocol and model combinations.
Step 4: Set execution boundaries
The server verifies material ownership, URL, quantity, duration and size; model output is not authorization. Set single task and session budgets, total wait caps, and limited polling. If the creation request times out, check the record first, and the agent will not automatically retry the charging task indefinitely. This site’s Key is not forwarded when downloading third-party results.
Step 5: Acceptance and recovery
First accept a picture or a short video, check the call record of this site and the final product, and then open the batch. After the Agent restarts, it will continue querying from the saved task ID; reaching the local waiting limit does not mean that the supplier task is cancelled. The failure result retains the desensitized error and request ID, and does not mark the semi-finished product as completed.