Quick Start

LLM API Quick Start

Use this LLM API quick start when you want to test WaveSpeedAI LLM quickly and make your first OpenAI-compatible Chat Completions request.

Option 1: Try It in the Playground

The fastest way to understand the service is through the web UI.

  1. Open wavespeed.ai/llm.
  2. Pick a model from the model selector.
  3. Send a short prompt.
  4. Adjust temperature, max tokens, or streaming if needed.
  5. Open View Code to copy an API example for the current model and settings.

The Playground is also the recommended place to confirm the latest model IDs, context windows, and prices.

Option 2: Call the OpenAI-Compatible API

WaveSpeedAI LLM uses the OpenAI Chat Completions format.

FieldValue
Base URLhttps://llm.wavespeed.ai/v1
Chat endpointhttps://llm.wavespeed.ai/v1/chat/completions
API keyYour WaveSpeedAI API key
ProtocolOpenAI-compatible Chat Completions
Rate limitVaries by account and model; read the response headers

Minimal cURL Request for the LLM API

curl --fail-with-body --connect-timeout 10 --max-time 120 \
  https://llm.wavespeed.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${WAVESPEED_API_KEY}" \
  -d '{
    "model": "deepseek/deepseek-v4-flash",
    "messages": [
      {
        "role": "user",
        "content": "Write a concise product description for WaveSpeedAI LLM."
      }
    ]
  }'

Python OpenAI SDK Example

import os
from openai import OpenAI
 
client = OpenAI(
    api_key=os.environ["WAVESPEED_API_KEY"],
    base_url="https://llm.wavespeed.ai/v1",
    timeout=120.0,
    max_retries=0,
)
 
try:
    response = client.chat.completions.create(
        model="deepseek/deepseek-v4-flash",
        messages=[
            {"role": "user", "content": "Give me three ways to reduce LLM cost."}
        ],
    )
except Exception as exc:
    raise SystemExit(f"LLM request failed: {exc}") from exc
 
if getattr(response, "error", None):
    raise RuntimeError(response.error)
print(response.choices[0].message.content)

JavaScript OpenAI SDK Example

import OpenAI from "openai";
 
const client = new OpenAI({
  apiKey: process.env.WAVESPEED_API_KEY,
  baseURL: "https://llm.wavespeed.ai/v1",
  timeout: 120_000,
  maxRetries: 0,
});
 
if (!process.env.WAVESPEED_API_KEY) throw new Error("Set WAVESPEED_API_KEY");
 
try {
  const response = await client.chat.completions.create({
    model: "deepseek/deepseek-v4-flash",
    messages: [
      { role: "user", content: "Summarize what an OpenAI-compatible API means." }
    ],
  });
 
  if (response.error) throw new Error(response.error.message || "LLM generation failed");
  console.log(response.choices[0]?.message?.content ?? "");
} catch (error) {
  console.error("LLM request failed:", error);
  process.exitCode = 1;
}

Long Responses, Keepalive, and Errors

Chat Completions, Completions, Responses, Messages, and native Gemini generation endpoints can send keepalive before the first model output, including while a provider response is pending. Errors detected before the response is committed retain their normal HTTP error status. After HTTP 200 has been sent, rejections or generation failures are reported in the response body.

For non-streaming requests, the response can contain leading JSON whitespace before the complete JSON object. Normal JSON parsers ignore this whitespace. After HTTP 200 has been sent, later failures are reported in the response body: check error even when HTTP status is 200. An error response includes a request ID for support; it is not a task ID or a guarantee that the result can be retrieved later. With an OpenAI SDK, check the returned object’s error field rather than relying only on exceptions. Likewise, curl --fail-with-body only detects HTTP error status, so callers must inspect a successful HTTP response body for error.

For streaming requests, ignore SSE comment frames such as : WAVESPEED PROCESSING. They keep the connection alive while generation is pending and contain no model output or token usage. Always inspect JSON events for error; Chat Completions errors can include a choice with finish_reason: "error". Do not treat an error event or an incomplete connection as a successful completion.

Keepalive does not override your application’s total timeout. The timeout in these examples is a client choice, not the service’s maximum generation time. Keepalive does not extend the provider’s own timeout or guarantee a successful generation.

The examples disable automatic retries to avoid resubmitting generation after an uncertain connection failure. A disconnected non-streaming request can continue running and be billed according to actual execution and usage. Do not assume disconnection means cancellation or a free request; only retry when you have determined the previous request’s outcome.

What to Change Next

ChangeField
Try another modelmodel
Make output shorter or longermax_tokens
Make output more focusedLower temperature
Make output more creativeRaise temperature
Stream output as it is generatedstream: true
Improve repeated long promptsKeep a stable prefix and see Prompt Caching

For production traffic, read the X-RateLimit-* response headers and handle rate-limit errors in both HTTP status and response bodies. Use bounded exponential backoff only for a confirmed rejection; do not automatically resubmit when the previous generation’s outcome is unknown. Limits can vary by account and model. If you need a higher limit, contact support@wavespeed.ai with the target models, expected request volume, peak RPM, and business or usage details for review.

Common Request Fields

Support for optional generation fields can vary by model. Start with model and messages, then add optional fields after testing the selected model.

FieldRequiredDescription
modelYesModel ID, such as deepseek/deepseek-v4-flash
messagesYesConversation messages in OpenAI chat format
streamNoReturn incremental chunks
max_tokensNoLimit output length
temperatureNoControl randomness
top_pNoNucleus sampling

Messages can include system, user, and assistant roles. Send previous turns again when you want the model to keep context.

Streaming Example

Use streaming when you want to show text as soon as it is generated.

import OpenAI from "openai";
 
const client = new OpenAI({
  apiKey: process.env.WAVESPEED_API_KEY,
  baseURL: "https://llm.wavespeed.ai/v1",
  timeout: 120_000,
  maxRetries: 0,
});
 
const stream = await client.chat.completions.create({
  model: "deepseek/deepseek-v4-flash",
  messages: [
    { role: "user", content: "Write a short onboarding checklist." }
  ],
  stream: true,
});
 
for await (const chunk of stream) {
  const error = chunk.error || chunk.choices?.find(choice => choice.error)?.error;
  if (error || chunk.choices?.some(choice => choice.finish_reason === "error")) {
    throw new Error(error?.message || "LLM generation failed");
  }
  process.stdout.write(chunk.choices[0]?.delta?.content || "");
}

Next Steps

© 2026 WaveSpeedAI. All rights reserved.