Use NextAPI as a custom tool in your LangChain agents. Wrap our REST API as a StructuredTool so any LangChain agent can generate videos as part of its execution chain.
Set the following values in your LangChain configuration:
import os
import requests
from langchain.tools import StructuredTool
from pydantic import BaseModel, Field
class VideoGenInput(BaseModel):
prompt: str = Field(description="Text description of the video to generate")
duration_seconds: int = Field(default=6, description="Video duration in seconds")
resolution: str = Field(default="1080p", description="Output resolution")
def generate_video(prompt: str, duration_seconds: int = 6, resolution: str = "1080p") -> str:
resp = requests.post(
"https://api.nextapi.top/v1/video/generations",
headers={
"Authorization": f"Bearer {os.environ['NEXTAPI_KEY']}",
"Content-Type": "application/json",
},
json={
"model": "seedance-2.0-pro",
"prompt": prompt,
"duration_seconds": duration_seconds,
"resolution": resolution,
},
)
resp.raise_for_status()
return resp.json()
nextapi_tool = StructuredTool.from_function(
func=generate_video,
name="nextapi_video_gen",
description="Generate an AI video from a text prompt using NextAPI",
args_schema=VideoGenInput,
)Verify your setup by running this command:
curl -X POST https://api.nextapi.top/v1/video/generations \
-H "Authorization: Bearer $NEXTAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedance-2.0-pro",
"prompt": "a butterfly landing on a flower in slow motion",
"duration_seconds": 6,
"resolution": "1080p"
}'Contact our integrations team at support@nextapi.dev or check the full API documentation.