> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xhuoapi.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Get your first XHuoAPI API call running in 5 minutes.

This walkthrough uses **Midjourney text-to-image** as the example: sign up → get a Token → call the API → read the result.

## 1. Sign up and grab credit

1. Register at [platform.xhuoapi.ai](https://api.xhuoapi.ai)
2. Open the **Midjourney** service detail page and purchase a package or claim a trial
3. On the **Credentials** tab, click **Create** and copy the returned Token

<Warning>
  The Token is a secret. **Never** paste it into frontend / mobile code or public repos — use env vars or a secrets manager.
</Warning>

## 2. Make the request

Export your Token:

```bash theme={null}
export XHuoAPI_API_TOKEN="your-token-here"
```

Call text-to-image:

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.xhuoapi.ai/v1/midjourney/imagine \
    -X POST \
    -H "Authorization: Bearer $XHuoAPI_API_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "prompt": "A cute cat sitting on a wooden table, soft lighting"
    }'
  ```

  ```python Python theme={null}
  import os, requests

  resp = requests.post(
      "https://api.xhuoapi.ai/v1/midjourney/imagine",
      headers={
          "Authorization": f"Bearer {os.environ['XHuoAPI_API_TOKEN']}",
          "Content-Type": "application/json",
      },
      json={"prompt": "A cute cat sitting on a wooden table, soft lighting"},
      timeout=300,
  )
  print(resp.json())
  ```

  ```javascript Node.js theme={null}
  const res = await fetch("https://api.xhuoapi.ai/v1/midjourney/imagine", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${process.env.XHuoAPI_API_TOKEN}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      prompt: "A cute cat sitting on a wooden table, soft lighting",
    }),
  });
  console.log(await res.json());
  ```
</CodeGroup>

## 3. Parse the response

`/midjourney/imagine` **waits for generation to finish before returning** (\~tens of seconds), so the body already contains the result:

```json theme={null}
{
  "success": true,
  "task_id": "27a1128f-14b5-440e-a82d-510c81e6fcd4",
  "image_id": "1211290228438868029",
  "image_url": "https://midjourney.cdn.xhuoapi.ai/.../image.png",
  "image_width": 1024,
  "image_height": 1024,
  "actions": ["upscale1", "upscale2", "variation1", "variation2", "..."]
}
```

* `image_url` is the 4-quadrant grid image — display or download it directly
* `actions` lists follow-up operations you can run on this image (upscale, variations)
* `task_id` is used for follow-up calls (upscale / variation)

On failure the body shape is different — it has **no** `success` field:

```json theme={null}
{
  "error": {
    "code": "invalid_token",
    "message": "The specified token is invalid or wrong."
  },
  "trace_id": "..."
}
```

For the full error table see [Response format](/en/concepts/responses).

## 4. Async: long video / long music

Heavier video and music endpoints typically return only a `task_id` and deliver the result via polling or webhook. See [Async task model](/en/concepts/async-tasks).

## 5. Where to go next

<CardGroup cols={2}>
  <Card title="API reference" icon="code" href="/en/api-reference">
    Interactive docs for every endpoint
  </Card>

  <Card title="Gateway & auth" icon="key" href="/en/authentication">
    Tokens, endpoints, error codes
  </Card>

  <Card title="Pricing overview" icon="dollar-sign" href="/en/pricing/overview">
    Billing model for each category
  </Card>

  <Card title="MCP integration" icon="plug" href="/en/mcp/overview">
    Call from Claude / Cursor directly
  </Card>
</CardGroup>
