Skip to content

Repository files navigation

langchain-wavespeed

LangChain integration for WaveSpeed AI — run state-of-the-art image and video generation models from your LangChain agents and chains.

Installation

pip install -U langchain-wavespeed

Set your API key (get one at wavespeed.ai):

export WAVESPEED_API_KEY="your-api-key"

Tools

WaveSpeedImageGeneration

Generate images from text prompts (defaults to bytedance/seedream-v5.0-pro):

fromlangchain_wavespeedimportWaveSpeedImageGenerationtool=WaveSpeedImageGeneration()
url=tool.invoke(
{
"prompt": "A red panda drinking boba tea, studio lighting",
"resolution": "2k", # optional: "1k" | "1.5k" | "2k""aspect_ratio": "16:9", # optional
}
)
print(url) # https://.../output.png

WaveSpeedVideoGeneration

Generate videos from text prompts (defaults to bytedance/seedance-2.5/text-to-video):

fromlangchain_wavespeedimportWaveSpeedVideoGenerationtool=WaveSpeedVideoGeneration()
url=tool.invoke({"prompt": "A drone shot over a glacier at sunrise", "duration": 5})

WaveSpeedRunModel

Run any model on the WaveSpeed platform by id (browse the catalog at wavespeed.ai/models):

fromlangchain_wavespeedimportWaveSpeedRunModeltool=WaveSpeedRunModel()
url=tool.invoke({
"model": "wavespeed-ai/z-image/turbo",
"input": {"prompt": "A lighthouse at dusk"},
})

Use with an agent

fromlangchain.agentsimportcreate_agentfromlangchain_wavespeedimportWaveSpeedImageGeneration, WaveSpeedVideoGenerationagent=create_agent(
"openai:gpt-5",
tools=[WaveSpeedImageGeneration(), WaveSpeedVideoGeneration()],
)
result=agent.invoke(
{"messages": [{"role": "user", "content": "Make me a picture of a corgi surfing."}]}
)

Configuration

All tools accept:

ParameterDefaultDescription
api_keyWAVESPEED_API_KEY env varWaveSpeed API key
modeltool-specificModel id to run (image/video tools)
timeout600.0Max seconds to wait for a prediction (None waits forever)
poll_interval2.0Seconds between result polls

When a prediction fails or times out, the tool raises ToolException with the platform's error text and the task id, so a paid task stays traceable (and an agent can read the failure instead of crashing the run). A timeout only stops the waiting - the task keeps running server-side.

await tool.ainvoke(...) works, but note that the underlying WaveSpeed SDK is synchronous: LangChain runs the blocking call in a worker thread, so it will not block your event loop, but it is not natively async I/O.

License

MIT


WaveSpeed AI — AI image & video generation platform. Try it in the browser: Image generator · Video generator

About

LangChain integration for WaveSpeed AI - image and video generation tools

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages