All Integrations

LangChain Integration

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.

Configuration

Set the following values in your LangChain configuration:

python
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,
)

Setup Steps

  1. 1Install dependencies: pip install langchain requests pydantic
  2. 2Set your API key: export NEXTAPI_KEY=your-key-here
  3. 3Define the VideoGenInput schema and generate_video function as shown above.
  4. 4Create a StructuredTool wrapping the function.
  5. 5Add the tool to your LangChain agent's tool list.
  6. 6The agent will call NextAPI when it decides video generation is needed.

Test with cURL

Verify your setup by running this command:

bash
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"
  }'

Need help?

Contact our integrations team at support@nextapi.dev or check the full API documentation.