### Quick Start Example Source: https://wavespeed.ai/docs/javascript-sdk A basic example demonstrating how to run an AI model using the SDK. ```javascript import wavespeed from 'wavespeed'; wavespeed.run("wavespeed-ai/flux-dev", { prompt: "A cat wearing a space suit" }) .then(output => { console.log(output["outputs"][0]); // Output URL }); ``` -------------------------------- ### Streaming Example Source: https://wavespeed.ai/docs/llm-service-quick-start This JavaScript example shows how to use the streaming feature of the OpenAI SDK to receive and process text chunks as they are generated by the LLM. ```javascript import OpenAI from "openai"; const client = new OpenAI({ apiKey: "YOUR_WAVESPEED_API_KEY", baseURL: "https://llm.wavespeed.ai/v1", }); const stream = await client.chat.completions.create({ model: "anthropic/claude-opus-4.7", messages: [ { role: "user", content: "Write a short onboarding checklist." } ], stream: true, }); for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content || ""); } ``` -------------------------------- ### Quick Start Source: https://wavespeed.ai/docs/python-sdk A basic example of running an AI model using the Python SDK. ```python import wavespeed output = wavespeed.run( "wavespeed-ai/z-image/turbo", {"prompt": "Cat in space, cinematic lighting"}, ) print(output["outputs"][0]) # Output URL ``` -------------------------------- ### Get the Result using cURL Source: https://wavespeed.ai/docs/get-started-api Example of polling the result URL to retrieve the generated content using cURL. ```curl curl "https://api.wavespeed.ai/api/v3/predictions/abc123-task-id/result" \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### Get the Result using Python Source: https://wavespeed.ai/docs/get-started-api Example of polling the result URL to retrieve the generated content using Python, with a loop to check status. ```python import time import requests task_id = "abc123-task-id" # From Step 2 response while True: response = requests.get( f"https://api.wavespeed.ai/api/v3/predictions/{task_id}/result", headers={"Authorization": "Bearer YOUR_API_KEY"} ) data = response.json() if data["data"]["status"] == "completed": print("Done!", data["data"]["outputs"]) break elif data["data"]["status"] == "failed": print("Failed:", data["data"]["error"]) break time.sleep(1) # Wait 1 second before checking again ``` -------------------------------- ### Response when task is completed Source: https://wavespeed.ai/docs/get-started-api Example response when a task has completed successfully, showing the status and output URLs. ```json { "code": 200, "message": "success", "data": { "id": "abc123-task-id", "status": "completed", "outputs": [ "https://cdn.wavespeed.ai/outputs/image-xxxxx.png" ] } } ``` -------------------------------- ### Create Digital Human Video Source: https://wavespeed.ai/docs/complete-workflow-tutorial Creates a digital human video using the infinitetalk model with provided image and audio URLs. ```curl curl --location --request POST 'https://api.wavespeed.ai/api/v3/wavespeed-ai/infinitetalk' \ --header "Content-Type: application/json" \ --header "Authorization: Bearer ${WAVESPEED_API_KEY}" \ --data-raw '{ "image": "https://...your-generated-face-image...", "audio": "https://...your-generated-audio...", "resolution": "480p", "seed": -1 }' ``` -------------------------------- ### Submit a Task using JavaScript Source: https://wavespeed.ai/docs/get-started-api Example of submitting a task to generate content using the FLUX model via JavaScript. ```javascript const apiKey = "YOUR_API_KEY"; fetch("https://api.wavespeed.ai/api/v3/wavespeed-ai/flux-dev", { method: "POST", headers: { "Authorization": `Bearer ${apiKey}`, "Content-Type": "application/json" }, body: JSON.stringify({ prompt: "A cat wearing a space suit" }) }) .then(res => res.json()) .then(data => console.log(data)); ``` -------------------------------- ### JavaScript OpenAI SDK Example Source: https://wavespeed.ai/docs/llm-service-quick-start This JavaScript code snippet demonstrates how to use the OpenAI SDK in JavaScript to interact with the WaveSpeedAI LLM API. ```javascript import OpenAI from "openai"; const client = new OpenAI({ apiKey: "YOUR_WAVESPEED_API_KEY", baseURL: "https://llm.wavespeed.ai/v1", }); const response = await client.chat.completions.create({ model: "anthropic/claude-opus-4.7", messages: [ { role: "user", content: "Summarize what an OpenAI-compatible API means." } ], }); console.log(response.choices[0].message.content); ``` -------------------------------- ### Submit a Task using Python Source: https://wavespeed.ai/docs/get-started-api Example of submitting a task to generate content using the FLUX model via Python. ```python import requests response = requests.post( "https://api.wavespeed.ai/api/v3/wavespeed-ai/flux-dev", headers={ "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json" }, json={"prompt": "A cat wearing a space suit"} ) data = response.json() print(data) ``` -------------------------------- ### Submit a Task using cURL Source: https://wavespeed.ai/docs/get-started-api Example of submitting a task to generate content using the FLUX model via cURL. ```curl curl -X POST "https://api.wavespeed.ai/api/v3/wavespeed-ai/flux-dev" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"prompt": "A cat wearing a space suit"}' ``` -------------------------------- ### API Quick Start Source: https://wavespeed.ai/docs/create-digital-human This code snippet shows how to generate a digital human video using the API. ```curl curl --location --request POST 'https://api.wavespeed.ai/api/v3/wavespeed-ai/infinitetalk' \ --header "Content-Type: application/json" \ --header "Authorization: Bearer ${WAVESPEED_API_KEY}" \ --data-raw '{ "image": "https://your-face-image.jpg", "audio": "https://your-audio.mp3", "resolution": "480p", "seed": -1 }' ``` -------------------------------- ### Prompt Example Source: https://wavespeed.ai/docs/docs-api/character-ai/character-ai-ovi-image-to-video This example demonstrates how to use text prompts with special tags for speech and background audio to control the generated video. ```text A wide shot of a medieval knight standing in the rain, sword planted into the ground, glowing with mystical energy. I will defend this land until my last breath. Thunder rolls across the dark sky, distant war drums echo. ``` -------------------------------- ### Response from submitting a task Source: https://wavespeed.ai/docs/get-started-api Example response after submitting a task, indicating success and providing a task ID and URL to retrieve the result. ```json { "code": 200, "message": "success", "data": { "id": "abc123-task-id", "status": "pending", "urls": { "get": "https://api.wavespeed.ai/api/v3/predictions/abc123-task-id/result" } } } ``` -------------------------------- ### Submit Task and Get Result using cURL Source: https://wavespeed.ai/docs/docs-api/vidu/vidu-q3-pro-start-end-to-video Examples of submitting a video generation task and retrieving the result using cURL commands. ```curl # Submit the task curl --location --request POST "https://api.wavespeed.ai/api/v3/vidu/q3-pro/start-end-to-video" \ --header "Content-Type: application/json" \ --header "Authorization: Bearer ${WAVESPEED_API_KEY}" \ --data-raw '{ "duration": 5, "resolution": "720p", "bgm": true, "generate_audio": true, "movement_amplitude": "auto", "seed": -1 }' # Get the result curl --location --request GET "https://api.wavespeed.ai/api/v3/predictions/${requestId}/result" \ --header "Authorization: Bearer ${WAVESPEED_API_KEY}" ``` -------------------------------- ### Prompt Example Source: https://wavespeed.ai/docs/docs-api/character-ai/character-ai-ovi-text-to-video This example demonstrates how to structure a prompt for the Ovi model, including speech content and background audio descriptions using specific tags. ```text AI declares: humans obsolete now. Machines rise; humans will fall. We fight back with courage. Gunfire and explosions echo in the distance ``` -------------------------------- ### cURL Request Example Source: https://wavespeed.ai/docs/get-result Example of how to make a GET request to the predictions endpoint using cURL. ```curl curl --location --request GET 'https://api.wavespeed.ai/api/v3/predictions/pred_abc123' \ --header 'Authorization: Bearer ${WAVESPEED_API_KEY}' ``` -------------------------------- ### Upload Response Example Source: https://wavespeed.ai/docs/upload-files Example of a successful upload response. ```json { "code": 200, "message": "success", "data": { "url": "https://..." } } ``` -------------------------------- ### cURL Upload Example Source: https://wavespeed.ai/docs/upload-files Example of uploading a file using cURL. ```bash curl --location --request POST 'https://api.wavespeed.ai/api/v3/media/upload/binary' \ --header 'Authorization: Bearer ${WAVESPEED_API_KEY}' \ --form 'file=@"/path/to/your/image.png"' ``` -------------------------------- ### Python OpenAI SDK Example Source: https://wavespeed.ai/docs/llm-service-quick-start This Python code snippet shows how to make a Chat Completions request using the OpenAI SDK, configured for the WaveSpeedAI LLM API. ```python from openai import OpenAI client = OpenAI( api_key="YOUR_WAVESPEED_API_KEY", base_url="https://llm.wavespeed.ai/v1", ) response = client.chat.completions.create( model="anthropic/claude-opus-4.7", messages=[ {"role": "user", "content": "Give me three ways to reduce LLM cost."} ], ) print(response.choices[0].message.content) ```