Skip to main content

Python client for WaveSpeed AI

Project description

WaveSpeed Python Client

A Python client for interacting with the WaveSpeed AI API.

Installation

pip install wavespeed

Usage

Synchronous Image Generation

from wavespeed import WaveSpeed

# Initialize the client with your API key (or set WAVESPEED_API_KEY environment variable)
client = WaveSpeed(api_key="YOUR_API_KEY")

# Generate an image and wait for the result
prediction = client.run(
    modelId="wavespeed-ai/flux-dev",
    input={
        "prompt": "A futuristic cityscape with flying cars and neon lights",
        "size": "1024*1024",
        "num_inference_steps": 28,
        "guidance_scale": 5.0,
        "num_images": 1,
        "seed": -1,
        "enable_safety_checker": True
    }
)

# Print the generated image URLs
for i, img_url in enumerate(prediction.outputs):
    print(f"Image {i+1}: {img_url}")

Asynchronous Image Generation

import asyncio
from wavespeed import WaveSpeed

async def generate_image():
    # Initialize the client with your API key (or set WAVESPEED_API_KEY environment variable)
    client = WaveSpeed(api_key="YOUR_API_KEY")
    
    try:
        # Generate an image and wait for the result
        prediction = await client.async_run(
            modelId="wavespeed-ai/flux-dev",
            input={
                "prompt": "A futuristic cityscape with flying cars and neon lights",
                "size": "1024*1024",
                "num_inference_steps": 28,
                "guidance_scale": 5.0,
                "num_images": 1,
                "seed": -1,
                "enable_safety_checker": True
            }
        )
        
        # Print the generated image URLs
        for i, img_url in enumerate(prediction.outputs):
            print(f"Image {i+1}: {img_url}")
    finally:
        # Always close the client when done
        await client.close()

# Run the async function
asyncio.run(generate_image())

Non-blocking Image Generation

You can also create a prediction without waiting for it to complete:

from wavespeed import WaveSpeed

# Initialize the client with your API key (or set WAVESPEED_API_KEY environment variable)
client = WaveSpeed(api_key="YOUR_API_KEY")

# Create a prediction without waiting
prediction = client.create(
    modelId="wavespeed-ai/flux-dev",
    input={
        "prompt": "A futuristic cityscape with flying cars and neon lights",
        "size": "1024*1024",
        "num_inference_steps": 28,
        "guidance_scale": 5.0,
        "num_images": 1,
        "seed": -1,
        "enable_safety_checker": True
    }
)

print(f"Prediction created with ID: {prediction.id}")
print(f"Initial status: {prediction.status}")

# Later, you can wait for the prediction to complete
result = prediction.wait()
print(f"Final status: {result.status}")

# Print the generated image URLs
for i, img_url in enumerate(result.outputs):
    print(f"Image {i+1}: {img_url}")

Command Line Examples

The package includes several example scripts that you can use to generate images:

Basic Image Generation

# Set your API key as an environment variable
export WAVESPEED_API_KEY="your_api_key_here"

# Run the example script
python examples/generate_image.py --prompt "A futuristic cityscape with flying cars and neon lights"

Asynchronous Image Generation

# Run the async example script
python examples/async_generate_image.py --prompt "A futuristic cityscape with flying cars and neon lights"

Non-blocking Image Generation

# Create a prediction and poll for status
python examples/create_generate_image.py --prompt "A futuristic cityscape with flying cars and neon lights"

Command Line Options

--prompt TEXT         Text description of the desired image (required)
--strength FLOAT      How much to transform the input image (0.0 to 1.0)
--size WIDTHxHEIGHT   Image dimensions (default: 1024*1024)
--steps INT           Number of inference steps (default: 28)
--guidance FLOAT      How closely to follow the prompt (default: 5.0)
--num-images INT      Number of images to generate (default: 1)
--seed INT            Random seed (-1 for random)
--safety              Enable content safety filtering

API Reference

WaveSpeed Client

WaveSpeed(api_key)

Parameters:

  • api_key (str): Your WaveSpeed API key

Methods

run

run(modelId, input, **kwargs) -> Prediction

Generate an image and wait for the result.

async_run

async_run(modelId, input, **kwargs) -> Prediction

Asynchronously generate an image and wait for the result.

create

create(modelId, input, **kwargs) -> Prediction

Create a prediction without waiting for it to complete.

async_create

async_create(modelId, input, **kwargs) -> Prediction

Asynchronously create a prediction without waiting for it to complete.

Prediction Model

The Prediction object contains information about an image generation job:

prediction.id           # Unique ID of the prediction
prediction.model        # Model ID used for the prediction
prediction.status       # Status of the prediction (processing, completed, failed)
prediction.input        # Input parameters used for the prediction
prediction.outputs      # List of output image URLs
prediction.urls.get    # URL to get the prediction status
prediction.has_nsfw_contents # List of booleans indicating if each image has NSFW content
prediction.created_at   # Creation timestamp
prediction.error        # Error message (if any)
prediction.executionTime # Time taken to execute the prediction in milliseconds

Methods

prediction.wait() -> Prediction  # Wait for the prediction to complete
prediction.reload() -> Prediction  # Reload the prediction status

# Async versions
await prediction.async_wait() -> Prediction
await prediction.async_reload() -> Prediction

Environment Variables

  • WAVESPEED_API_KEY: Your WaveSpeed API key
  • WAVESPEED_POLL_INTERVAL: Interval in seconds for polling prediction status (default: 0.5)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wavespeed-0.0.5.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wavespeed-0.0.5-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file wavespeed-0.0.5.tar.gz.

File metadata

  • Download URL: wavespeed-0.0.5.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.11

File hashes

Hashes for wavespeed-0.0.5.tar.gz
Algorithm Hash digest
SHA256 2cb12e8e3e867d5d6187af08002a698c517d1cc8fff8694f1cd54f3d8ea457e1
MD5 b80a94f54bbbe6627ff3e91cb1a95244
BLAKE2b-256 3d9092bb73210adbff982af83ad6810badf40c40a2a5769addfcd56ff860d4d2

See more details on using hashes here.

File details

Details for the file wavespeed-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: wavespeed-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.11

File hashes

Hashes for wavespeed-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d52f6233c21d48e96e1b38fd6494352ce161d0ba7fa0c823eec3c55b0a482b17
MD5 863d14bebfbb2d2ec02b827ff99f34d7
BLAKE2b-256 e8bc2ab13b1f0cca705b64f0ad358018ba4fd5e19eb90f9b04edc6d66e28af81

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page