> ## 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.

# Luma Tasks API의 연동 및 사용

> Luma Video Generation 集成指南 - XHuoAPI

Luma Tasks API의 주요 기능은 Luma Videos Generation API에서 생성된 작업 ID를 입력하여 해당 작업의 실행 상태를 조회하는 것입니다.

본 문서는 Luma Tasks API의 연동 설명을 자세히 소개하여, 귀하가 이 API의 강력한 기능을 쉽게 통합하고 충분히 활용할 수 있도록 돕습니다. Luma Tasks API를 통해 Luma Videos Generation API의 작업 실행 상태를 쉽게 조회할 수 있습니다.

## 신청 절차

Luma Tasks API를 사용하려면 먼저 신청 페이지 [Luma Videos Generation API](https://api.xhuoapi.ai/documents/5bd3597d-1ff8-44ad-a580-b66b48393e7f)에서 해당 서비스를 신청한 후, Luma Videos Generation API의 작업 ID를 복사해야 합니다. 아래 그림과 같이:

![](https://cdn.xhuoapi.ai/ynk4ow.png)

마지막으로 Tasks API 페이지 [Luma Tasks API](https://api.xhuoapi.ai/documents/7d32369c-4ead-4364-a4c5-652bc768b3ff)에서 해당 서비스를 신청하고, 페이지에 들어가면 "Acquire" 버튼을 클릭합니다. 아래 그림과 같이:

![신청 페이지](https://cdn.xhuoapi.ai/rci31i.png)

로그인 또는 등록이 되어 있지 않은 경우, 자동으로 [로그인 페이지](https://api.xhuoapi.ai)로 리디렉션되어 등록 및 로그인을 요청합니다. 로그인 및 등록 후에는 자동으로 현재 페이지로 돌아옵니다.

첫 신청 시 무료 한도가 제공되어, 해당 API를 무료로 사용할 수 있습니다.

## 요청 예시

Luma Tasks API는 Luma Videos Generation API의 결과를 조회하는 데 사용할 수 있습니다. Luma Videos Generation API 사용 방법에 대한 자세한 내용은 문서 [Luma Videos Generation API](https://api.xhuoapi.ai/documents/16bb0108-1f09-45b3-97ac-16a668750a8c)를 참조하십시오.

Luma Videos Generation API 서비스에서 반환된 작업 ID를 예로 들어, 해당 API를 사용하는 방법을 시연합니다. 가정해 보겠습니다. 작업 ID가 50fc6182-fa86-4c7d-ac12-2fa27ec2f151이라고 할 때, 다음과 같이 작업 ID를 전달하여 사용합니다.

### 작업 예시 그림

<p>
  <img src="https://cdn.xhuoapi.ai/frcrux.png" width="500" className="m-auto" />
</p>

### 요청 헤더 및 요청 본문 설정

**Request Headers**에는 다음이 포함됩니다:

* `accept`: JSON 형식의 응답 결과를 수신하도록 지정하며, 여기서는 `application/json`으로 입력합니다.
* `authorization`: API 호출에 필요한 키로, 신청 후 직접 드롭다운에서 선택할 수 있습니다.

**Request Body**에는 다음이 포함됩니다:

* `id`: 업로드된 작업 ID.
* `action`: 작업의 조작 방식.

아래 그림과 같이 설정합니다:

<p>
  <img src="https://cdn.xhuoapi.ai/g6ev5b.png" width="500" className="m-auto" />
</p>

### 코드 예시

페이지 오른쪽에서 다양한 언어의 코드가 자동으로 생성된 것을 확인할 수 있습니다. 아래 그림과 같이:

<p>
  <img src="https://cdn.xhuoapi.ai/i4fxqf.png" width="500" className="m-auto" />
</p>

일부 코드 예시는 다음과 같습니다:

#### CURL

```bash theme={null}
curl -X POST 'https://api.xhuoapi.ai/v1/luma/tasks' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "id": "50fc6182-fa86-4c7d-ac12-2fa27ec2f151",
  "action": "retrieve"
}'
```

#### Python

```python theme={null}
import requests

url = "https://api.xhuoapi.ai/v1/luma/tasks"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "id": "50fc6182-fa86-4c7d-ac12-2fa27ec2f151",
    "action": "retrieve"
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)
```

### 응답 예시

요청이 성공하면, API는 이 비디오 작업의 세부 정보를 반환합니다. 예를 들어:

```json theme={null}
{
  "_id": "66d297a3550a4144a5a5db42",
  "id": "50fc6182-fa86-4c7d-ac12-2fa27ec2f151",
  "api_id": "94fc9028-5a9f-4875-aae4-38463bd30ac5",
  "application_id": "06484a45-9d04-498a-98a7-67086dee8166",
  "created_at": 1725077411.961,
  "credential_id": "e6a879e5-a7c0-4f7b-9d6f-f9a837421a50",
  "request": {
    "action": "generate",
    "prompt": "우주에서 화산으로 이동하는 우주비행사"
  },
  "trace_id": "0b7c1c1a-045c-4145-a434-609cba88f0a9",
  "user_id": "ad7afe47-cea9-4cda-980f-2ad8810e51cf",
  "response": {
    "success": true,
    "task_id": "50fc6182-fa86-4c7d-ac12-2fa27ec2f151",
    "video_id": "4b088fc8-2bbc-4706-80a6-a0fb118adc1a",
    "prompt": "우주에서 화산으로 이동하는 우주비행사",
    "video_url": "https://platform.cdn.xhuoapi.ai/luma/50fc6182-fa86-4c7d-ac12-2fa27ec2f151.mp4",
    "video_height": 752,
    "video_width": 1360,
    "state": "completed",
    "thumbnail_url": "https://platform.cdn.xhuoapi.ai/luma/50fc6182-fa86-4c7d-ac12-2fa27ec2f151.jpg",
    "thumbnail_width": 1360,
    "thumbnail_height": 752
  },
  "finished_at": 1725077566.241
}
```

반환 결과는 여러 필드로 구성되어 있으며, request 필드는 작업을 시작할 때의 request body를 나타내고, response 필드는 작업 완료 후 반환된 response body로, 결과는 Luma Videos Generation API의 요청 및 반환과 일치합니다. 필드 설명은 다음과 같습니다.

* `id`: 이 비디오 작업을 생성한 ID로, 이번 비디오 생성 작업을 고유하게 식별하는 데 사용됩니다.
* `video_id`: 이곳에서 조회한 비디오 작업의 비디오 고유 식별자로, 다음에 비디오에 대한 확장 작업을 수행할 때 이 매개변수를 전달해야 합니다.
* `request`: 비디오 작업에서의 요청 정보를 조회합니다.
* `response`: 비디오 작업에서의 반환 정보를 조회합니다.

## 배치 조회 작업

이는 여러 작업 ID에 대해 비디오 작업 세부 정보를 조회하는 것으로, 위와는 다르게 action을 retrieve\_batch로 선택해야 합니다.

**Request Body**에는 다음이 포함됩니다:

* `ids`: 업로드된 작업 ID 배열.
* `action`: 작업의 조작 방식.

아래 그림과 같이 설정합니다:

<p>
  <img src="https://cdn.xhuoapi.ai/mpcf1m.png" width="500" className="m-auto" />
</p>

### 코드 예시

페이지 오른쪽에서 다양한 언어의 코드가 자동으로 생성된 것을 확인할 수 있습니다. 아래 그림과 같이:

<p>
  <img src="https://cdn.xhuoapi.ai/zs6y35.png" width="500" className="m-auto" />
</p>

일부 코드 예시는 다음과 같습니다:

### 응답 예시

요청이 성공하면, API는 이번 모든 배치 비디오 작업의 구체적인 세부 정보를 반환합니다. 예를 들어:

```json theme={null}
{
  "items": [
    {
      "_id": "66d297a3550a4144a5a5db42",
      "id": "50fc6182-fa86-4c7d-ac12-2fa27ec2f151",
      "api_id": "94fc9028-5a9f-4875-aae4-38463bd30ac5",
      "application_id": "06484a45-9d04-498a-98a7-67086dee8166",
      "created_at": 1725077411.961,
      "credential_id": "e6a879e5-a7c0-4f7b-9d6f-f9a837421a50",
      "request": {
        "action": "generate",
        "prompt": "우주에서 화산으로 이동하는 우주비행사"
      },
      "trace_id": "0b7c1c1a-045c-4145-a434-609cba88f0a9",
      "user_id": "ad7afe47-cea9-4cda-980f-2ad8810e51cf",
      "response": {
        "success": true,
        "task_id": "50fc6182-fa86-4c7d-ac12-2fa27ec2f151",
        "video_id": "4b088fc8-2bbc-4706-80a6-a0fb118adc1a",
        "prompt": "우주에서 화산으로 이동하는 우주비행사",
        "video_url": "https://platform.cdn.xhuoapi.ai/luma/50fc6182-fa86-4c7d-ac12-2fa27ec2f151.mp4",
        "video_height": 752,
        "video_width": 1360,
        "state": "completed",
        "thumbnail_url": "https://platform.cdn.xhuoapi.ai/luma/50fc6182-fa86-4c7d-ac12-2fa27ec2f151.jpg",
        "thumbnail_width": 1360,
        "thumbnail_height": 752
      },
      "finished_at": 1725077566.241
    },
    {
      "_id": "66d29ed3550a4144a5a6c089",
      "id": "76a05f61-68ad-4c1a-838f-a00cd08cf65b",
      "api_id": "94fc9028-5a9f-4875-aae4-38463bd30ac5",
      "application_id": "06484a45-9d04-498a-98a7-67086dee8166",
      "created_at": 1725079250.921,
      "credential_id": "e6a879e5-a7c0-4f7b-9d6f-f9a837421a50",
      "request": {
        "action": "generate",
        "prompt": "라 라 라"
      },
      "trace_id": "338f1616-741d-40b6-8d62-c025434024c6",
      "user_id": "ad7afe47-cea9-4cda-980f-2ad8810e51cf",
      "response": {
        "success": true,
        "task_id": "76a05f61-68ad-4c1a-838f-a00cd08cf65b",
        "video_id": "5a638d6a-7481-4c5e-8843-36c9d1b5bcd5",
        "prompt": "라 라 라",
        "video_url": "https://platform.cdn.xhuoapi.ai/luma/76a05f61-68ad-4c1a-838f-a00cd08cf65b.mp4",
        "video_height": 752,
        "video_width": 1360,
        "state": "completed",
        "thumbnail_url": "https://platform.cdn.xhuoapi.ai/luma/76a05f61-68ad-4c1a-838f-a00cd08cf65b.jpg",
        "thumbnail_width": 1360,
        "thumbnail_height": 752
      },
      "finished_at": 1725079406.71
    }
  ],
  "count": 2
}
```

#### CURL

```bash theme={null}
curl -X POST 'https://api.xhuoapi.ai/v1/luma/tasks' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "ids": ["50fc6182-fa86-4c7d-ac12-2fa27ec2f151","76a05f61-68ad-4c1a-838f-a00cd08cf65b"],
  "action": "retrieve_batch"
}'
```

#### Python

```python theme={null}
import requests

url = "https://api.xhuoapi.ai/v1/luma/tasks"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "ids": ["50fc6182-fa86-4c7d-ac12-2fa27ec2f151","76a05f61-68ad-4c1a-838f-a00cd08cf65b"],
    "action": "retrieve_batch"
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)
```

## 오류 처리

API를 호출할 때 오류가 발생하면, API는 해당 오류 코드와 정보를 반환합니다. 예를 들어:

* `400 token_mismatched`：잘못된 요청, 누락되었거나 잘못된 매개변수 때문일 수 있습니다.
* `400 api_not_implemented`：잘못된 요청, 누락되었거나 잘못된 매개변수 때문일 수 있습니다.
* `401 invalid_token`：권한 없음, 잘못되었거나 누락된 인증 토큰입니다.
* `429 too_many_requests`：요청이 너무 많음, 비율 제한을 초과했습니다.
* `500 api_error`：내부 서버 오류, 서버에서 문제가 발생했습니다.

### 오류 응답 예시

```json theme={null}
{
  "success": false,
  "error": {
    "code": "api_error",
    "message": "가져오기 실패"
  },
  "trace_id": "2cf86e86-22a4-46e1-ac2f-032c0f2a4e89"
}
```

## 결론

이 문서를 통해 Luma Tasks API를 사용하여 단일 또는 배치 비디오 작업의 모든 구체적인 세부 정보를 쿼리하는 방법을 이해하셨습니다. 이 문서가 API를 더 잘 연결하고 사용하는 데 도움이 되기를 바랍니다. 질문이 있으시면 언제든지 기술 지원 팀에 문의해 주십시오.
