Notice: Black Friday 2026 × Cyber Monday: Get up to 30% extra on top-ups, DeepSeek free to use · View the promotion
Blog

Tutorial

How to Use meshy-7.1/image-to-3d via the HiAPI API: curl, Python, and a Working Request

Nov 25, 2026 9 min read
扁平几何封面图:深松绿色背景上,几块大型棱镜被干脆的斜线分割成鼠尾草绿与暗绿色块,整体均衡克制。
On this page

What the meshy-7.1 image-to-3d workflow looks like

meshy-7.1/image-to-3d turns a single image into a downloadable 3D asset, typically a GLB file. It is not a synchronous call that returns a model in one response. Like most heavy generative workloads, it runs as an asynchronous job: you submit an image, the platform queues the work, and you poll a task until it produces an output URL.

That shape drives your whole integration. There are three distinct steps, and each maps to a different request:

  1. Submit. You POST your image (as a URL or a base64 payload, depending on the input schema) to the image-to-3d endpoint. The call returns quickly with a task identifier.
  2. Poll. You GET the task status using that identifier. The task moves through states such as queued, running, succeeded, and failed.
  3. Download. When the task succeeds, the response contains a URL to the generated GLB. You fetch that URL and hand the bytes to your own storage or pipeline.

Because generation is not instant, your code has to tolerate waiting. Design for a polling loop with a timeout, not a single blocking request. Build the submit step so it is safe to retry on network errors, and keep a record of the task ID so a crashed worker can resume polling instead of resubmitting — and paying — twice.

This mental model is what the rest of the guide implements. Each section below is one piece of that loop: credentials first, then submit, then poll, then download. The model page for meshy-7.1/image-to-3d is the reference for the exact input fields and output schema you should confirm before shipping.

Prepare your API key and base URL

Every request goes through the HiAPI unified endpoint, so you need two things: an API key and the base URL you prefix all paths with. Keep the key out of source control. Load it from an environment variable so the examples below run as written:

export HIAPI_API_KEY="your_api_key_here"
export HIAPI_BASE_URL="https://api.hiapi.ai/v1"

If your account or workspace gives you a different base URL, set it there rather than hardcoding it in code. The snippets use $HIAPI_BASE_URL and Authorization: Bearer $HIAPI_API_KEY consistently.

In Python, read the same variables so credentials never appear in the file:

import os

API_KEY = os.environ["HIAPI_API_KEY"]
BASE_URL = os.environ["HIAPI_BASE_URL"].rstrip("/")
HEADERS = {"Authorization": f"Bearer {API_KEY}"}

Two habits pay off here. First, validate that both variables are set at startup and fail loudly if not — a missing key produces a confusing authentication error deep in a request otherwise. Second, keep the base URL free of a trailing slash so path joins are predictable. Once credentials are in place, the submit step is the first real call.

Submit an image with a curl request

The submit call creates the task. It is a POST to the image-to-3d endpoint with your image and any generation parameters in the body. The image can be supplied as a publicly reachable URL or, where the schema allows, as inline data; use a URL for the simplest first test.

curl -sS -X POST "$HIAPI_BASE_URL/meshy-7.1/image-to-3d" \
  -H "Authorization: Bearer $HIAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "image_url": "https://example.com/sample-chair.png",
    "output_format": "glb"
  }'

The exact field names — image_url versus a base64 field, and which parameters are optional — are defined by the model schema. Check the model reference and keep your payload aligned with it; a single misspelled key usually surfaces as a validation error rather than a silent default.

A successful submit returns a task object. Extract and store the task identifier from the response, because every later call depends on it:

{
  "task_id": "task_abc123",
  "status": "queued"
}

Treat the submit call as only half of a transaction. Log the task_id alongside the input image reference before you poll, so that if the process dies you can look the task up rather than regenerate. If the request fails at the transport layer (timeout, connection reset), retrying is generally safe because no task was created — but if it fails after the server accepted it, you may get a duplicate task. Storing the ID immediately is what lets you detect and reconcile that case.

Submit the same task from Python

The Python version is a thin wrapper around the same request. Use requests with the shared headers and let a small function isolate the submit step so you can call it from a job runner, an API handler, or a script.

import os
import requests

API_KEY = os.environ["HIAPI_API_KEY"]
BASE_URL = os.environ["HIAPI_BASE_URL"].rstrip("/")
HEADERS = {"Authorization": f"Bearer {API_KEY}"}

def submit_image_to_3d(image_url: str, output_format: str = "glb") -> str:
    """Create an image-to-3d task and return its task_id."""
    payload = {"image_url": image_url, "output_format": output_format}
    resp = requests.post(
        f"{BASE_URL}/meshy-7.1/image-to-3d",
        headers=HEADERS,
        json=payload,
        timeout=30,
    )
    resp.raise_for_status()
    data = resp.json()
    task_id = data.get("task_id")
    if not task_id:
        raise RuntimeError(f"No task_id in response: {data}")
    return task_id

if __name__ == "__main__":
    tid = submit_image_to_3d("https://example.com/sample-chair.png")
    print("submitted task:", tid)

A few details matter in production. Set an explicit timeout so a stalled connection does not hang your worker. Call raise_for_status() so HTTP errors become exceptions you can catch and classify. And guard on the presence of task_id rather than assuming a 200 always carries one — a malformed success response is easier to detect here than three steps later.

Wrap the submit in a try/except for requests.RequestException in your job layer so transient network failures retry with backoff, while 4xx responses (bad image URL, invalid parameter) fail fast without retrying.

Poll the task and handle status and errors

Polling is where most integrations either work smoothly or quietly misbehave. The goal is a loop that waits long enough for generation but does not hammer the API or wait forever. Use a fixed or mildly increasing interval and an overall deadline.

import time
import requests

def wait_for_task(task_id: str, timeout_s: int = 300, interval_s: int = 5) -> dict:
    deadline = time.time() + timeout_s
    while time.time() < deadline:
        resp = requests.get(
            f"{BASE_URL}/meshy-7.1/image-to-3d/{task_id}",
            headers=HEADERS,
            timeout=30,
        )
        resp.raise_for_status()
        task = resp.json()
        status = task.get("status")

        if status == "succeeded":
            return task
        if status == "failed":
            raise RuntimeError(f"Task {task_id} failed: {task.get('error')}")

        time.sleep(interval_s)

    raise TimeoutError(f"Task {task_id} did not finish within {timeout_s}s")

The status values are the contract: terminal states (succeeded, failed) end the loop, everything else means keep waiting. Poll every few seconds — generation takes time, so a tight loop only wastes quota and can trigger rate limiting. Log the status on each iteration so you can tell "still running" apart from "stuck."

Handle failures at three levels. A task-level failed state carries an error reason; surface it, do not retry blindly — the same image will likely fail again. A transient HTTP error during a poll (5xx, timeout) is safe to retry after backoff, since polling is read-only. A local timeout means the task may still finish; do not cancel it in a hasty retry — reuse the stored task_id and poll again later rather than submitting a fresh job.

Download and use the GLB asset

When the task reaches succeeded, the response includes the location of the generated model. That URL is typically time-limited, so download promptly and store the bytes yourself rather than persisting the link.

def download_glb(task: dict, path: str = "output.glb") -> str:
    url = task.get("output_url") or task.get("result", {}).get("glb_url")
    if not url:
        raise RuntimeError(f"No GLB URL in task: {task}")
    with requests.get(url, stream=True, timeout=60) as r:
        r.raise_for_status()
        with open(path, "wb") as f:
            for chunk in r.iter_content(chunk_size=8192):
                f.write(chunk)
    return path

Before handing the file downstream, do a light sanity check. Confirm the downloaded content is non-empty and begins with the GLB binary signature (glTF), which catches HTML error pages masquerading as a 200. Record the source task_id next to the stored asset so the file is traceable back to its generating request.

Once the GLB is on your side, it is just a file: push it to your object store, attach it to a database row, or feed it into a viewer. Because you copied it off the temporary URL, the asset does not expire out from under you.

Troubleshooting common integration issues

Most problems cluster around three areas. Each has a cheap fix.

Input images. The image URL must be reachable by the service, not just your laptop. Private buckets and localhost URLs fail. Use an accessible link, verify it loads in an incognito window, and keep images reasonably sized — very large inputs slow processing or get rejected.

Polling behavior. Symptoms include endless queued states or rate-limit errors. Check that you are polling the right task ID, that intervals are not too tight, and that your timeout is generous enough for real generation time. If a worker restarts, resume from the stored task_id rather than resubmitting.

Expired results. If the download fails with a 403 or 404, the output URL has lapsed. The asset was generated but the link is gone — return to the finished task and re-request the download rather than regenerating, since you already paid for that job.

When something fails, read the error body before retrying. A validation error and a transient network fault need opposite responses, and the quickest path to a stable integration is treating them differently from the first line of code. For exact field names and status values, keep the meshy-7.1/image-to-3d model page open as you build.

Related articles

View all articles →

Start building with persistent AI artifacts

Get your API key and call image, video and audio models through one task-based API.

Read the API docs