For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs.
跳至內容

cURL

Learn how to call ApiSmart APIs with cURL, including model discovery, text generation, image generation, local image uploads, streaming, and asynchronous video tasks.

cURL is a command-line tool for sending HTTP requests and is one of the fastest ways to test the ApiSmart API.

This guide shows how to authenticate requests, retrieve available models, and call text, image, and video APIs directly from your terminal.

🚀 Before You Start

Make sure you have:

  • An ApiSmart account

  • An active API Key

  • Sufficient wallet balance for paid requests

  • cURL installed on your system

You can verify that cURL is available with:

curl --version

🔑 Set Your API Key

ApiSmart uses Bearer authentication.

You can place your API Key directly in a request:

Authorization: Bearer <your-api-key>

For local testing, you can also store the key in an environment variable instead of repeating it in every command.

macOS and Linux

Then use:

Windows PowerShell

Then use:

Keep your API Key private and do not include it in public repositories, screenshots, or shared command history.

🔗 API Base URL

The standard ApiSmart API Base URL is:

Most examples in this guide use the full endpoint URL so they can be copied and tested directly.

🧩 Get Available Models

Before sending a generation request, you can retrieve the latest model IDs with:

Example response:

Use the returned data[].id value as the model parameter in supported requests.

Model IDs must match exactly. Periods (.), hyphens (-), and version numbers must be copied exactly as returned or documented.

For more information, see Models and Model IDs.

💬 Chat Completions

Use:

Example:

For complete request behavior, see Chat Completions API.

🌊 Stream a Text Response

Add:

to the request body:

For an overview of streaming behavior, see Response Modes.

🖼️ Generate an Image

Use:

Example:

Image generation is synchronous by default and may take longer than a typical text request.

Set your client timeout to at least 90 seconds. The example above uses --max-time 120 to provide additional time for generation.

For image parameters and supported workflows, see Image Generation API.

🔄 Generate from a Reference Image

Pass a public image URL using image:

Multiple image URLs can also be provided as an array where supported.

📤 Upload a Local Image

To upload a local image file, use:

This endpoint uses multipart form data instead of a JSON request body.

With -F, cURL automatically creates the multipart request.

Each uploaded image file must meet the limits documented in Image Generation API.

🌊 Stream Image Generation

Supported image workflows can use SSE streaming.

When using cURL, add -N to prevent output buffering:

For supported streaming workflows, see Image Generation API and Response Modes.

🎬 Create a Video Task

Video generation is asynchronous.

Create a task with:

Example:

The response returns a task ID that you can use to check generation status.

For video models where resolution and duration affect billing, specify them explicitly rather than relying on default values.

🔄 Check Video Task Status

After creating a task, query it with:

Example:

Common task statuses include:

  • queued

  • running

  • succeeded

  • failed

  • cancelled

  • expired

Continue polling while the task is queued or running.

For complete video workflows, see Video Generation API.

🕘 Retrieve Recent Generated Media

You can also use cURL to retrieve recent generated media.

Images

Videos

For field definitions and history limits, see Generated Media History.

🛠️ Common cURL Options

Option
Purpose

-H

Add an HTTP request header

-d

Send a request body

-F

Send multipart form data or upload files

-N

Disable output buffering for streaming

--max-time

Set the maximum request duration

-X

Explicitly specify an HTTP method when needed

For most JSON POST requests using -d, cURL automatically sends a POST request, so -X POST is usually optional.

⚠️ Common Errors

401 invalid_api_key

Check that the API Key is valid and that the request includes:

402 insufficient_quota

Your account does not have sufficient available balance.

403 model_not_allowed

The selected model is not currently available to your API Key or account.

400 unsupported_resolution

The requested resolution is not supported by the selected video model.

503

A 503 can indicate a temporary service issue.

If it occurs after selecting a model, also verify that the model ID is written exactly as documented.

For complete error handling guidance, see HTTP Status Codes and API Errors.

✅ Quick cURL Checklist

Before sending a request, verify that:

  • Your API Key is active

  • The Authorization header uses Bearer

  • The endpoint is correct

  • JSON requests include Content-Type: application/json

  • The model ID is copied exactly

  • File uploads use -F instead of a JSON body

  • Image requests use an appropriate timeout

  • Video workflows poll the returned task ID

  • Your wallet has sufficient balance

➡️ Next Steps

Continue with:

最後更新於

這有幫助嗎?