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

# Quickstart

> Get started with Legnext AI API

<Note>
  **Building with AI?** Drop [`llms-full.txt`](https://docs.legnext.ai/llms-full.txt) into Cursor, Claude, ChatGPT, or any LLM-powered editor to load the entire Legnext API spec — every endpoint, parameter, and example — in one shot. See [`llms.txt`](https://docs.legnext.ai/llms.txt) for the index.
</Note>

<iframe className="w-full aspect-video rounded-xl" src="https://www.youtube.com/embed/CaECZdJFIHU" title="YouTube video player" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen />

## 1. Generate an API Key

Get your API key from the Legnext dashboard to authenticate your requests.

<Warning>
  Never share your API key with anyone. Keep it secure and never commit it to version control.
</Warning>

## 2. Set URL and Endpoint

All API requests are made to our base URL with specific endpoints:

```
https://api.legnext.ai/api/v1/{endpoint}
```

For example: `https://api.legnext.ai/api/v1/diffusion`

## 3. Headers

All API requests must include the following headers:

| Header         | Required | Description                     |
| -------------- | -------- | ------------------------------- |
| `x-api-key`    | Yes      | Your API key for authentication |
| `Content-Type` | No       | Set to `application/json`       |

## 4. Make Your First API Call

Generate your first image using our text-to-image endpoint:

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://api.legnext.ai/api/v1/diffusion" \
    -H "x-api-key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "text": "A beautiful sunset over mountains with vibrant colors",
      "callback": "https://your-domain.com/webhook"
    }'
  ```

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

  url = "https://api.legnext.ai/api/v1/diffusion"
  headers = {
      "x-api-key": "YOUR_API_KEY",
      "Content-Type": "application/json"
  }
  data = {
      "text": "A beautiful sunset over mountains with vibrant colors",
      "callback": "https://your-domain.com/webhook"
  }

  response = requests.post(url, headers=headers, json=data)
  result = response.json()
  print(result)
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.legnext.ai/api/v1/diffusion', {
    method: 'POST',
    headers: {
      'x-api-key': 'YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      text: 'A beautiful sunset over mountains with vibrant colors',
      callback: 'https://your-domain.com/webhook'
    })
  });

  const result = await response.json();
  console.log(result);
  ```
</CodeGroup>

## 5. Response Format

All endpoints return a Job object containing:

* `job_id`: Unique job identifier
* `status`: Processing status (pending, processing, completed, failed)
* `output`: Contains result image URLs when completed
* `meta`: Usage and timing information
* `error`: Error details if task failed

## 6. Error Codes & Handling

When a request fails, the API returns an HTTP error status code along with an error object:

```json theme={null}
{
  "code": 401,
  "message": "Failed to verify api key",
  "raw_message": "",
  "detail": null
}
```

### HTTP Status Codes

| Code  | Description           | Solution                                                                                   |
| ----- | --------------------- | ------------------------------------------------------------------------------------------ |
| `400` | Bad Request           | Invalid request parameters or malformed request body. Check your input parameters          |
| `401` | Unauthorized          | Authentication failed. Verify your API key is valid and included in the `x-api-key` header |
| `402` | Payment Required      | Insufficient credits in your account. Top up your balance or upgrade your plan             |
| `403` | Forbidden             | Sensitive content detected or permission denied. Review content policy guidelines          |
| `413` | Payload Too Large     | File size exceeds maximum limit. Reduce file size and try again                            |
| `422` | Unprocessable Entity  | Invalid parameter values or validation failed. Check parameter formats and values          |
| `429` | Too Many Requests     | Rate limit exceeded. Reduce request frequency or upgrade your plan                         |
| `500` | Internal Server Error | Temporary server issue. The request will be automatically retried                          |

<Tip>
  All error responses include a `code` field matching the HTTP status code and a `message` field with a human-readable description. Check these fields to understand what went wrong.
</Tip>

## 7. Next Steps

* Explore our [comprehensive endpoint documentation](/api-reference/image-generation/diffusion) for detailed parameters and examples
* Learn about [task status checking](/api-reference/task-management/get-task) for monitoring your requests
* Browse all available [image and video generation features](/getting-started/overview)

Start exploring our powerful image generation capabilities!

## Important

Please read our [Notice](/getting-started/notice) before using the API to understand supported models and current limitations.
