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

# タスクステータスの取得

>  - 非同期タスクの実行ステータスと結果をクエリ
- リアルタイムのステータス更新と進捗追跡
- タスク完了時に生成結果を取得
- 多言語対応（zh/en/ko/ja） 

<RequestExample>
  ```bash cURL theme={null}
  curl --request GET \
    --url https://api.apimart.ai/v1/tasks/task-unified-1757156493-imcg5zqt?language=ja \
    --header 'Authorization: Bearer <token>'
  ```

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

  url = "https://api.apimart.ai/v1/tasks/task-unified-1757156493-imcg5zqt"

  headers = {
      "Authorization": "Bearer <token>"
  }

  params = {
      "language": "ja"
  }

  response = requests.get(url, headers=headers, params=params)

  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const url = "https://api.apimart.ai/v1/tasks/task-unified-1757156493-imcg5zqt?language=ja";

  const headers = {
    "Authorization": "Bearer <token>"
  };

  fetch(url, {
    method: "GET",
    headers: headers
  })
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));
  ```

  ```go Go theme={null}
  package main

  import (
      "fmt"
      "io/ioutil"
      "net/http"
  )

  func main() {
      url := "https://api.apimart.ai/v1/tasks/task-unified-1757156493-imcg5zqt?language=ja"

      req, _ := http.NewRequest("GET", url, nil)
      req.Header.Set("Authorization", "Bearer <token>")

      client := &http.Client{}
      resp, err := client.Do(req)
      if err != nil {
          panic(err)
      }
      defer resp.Body.Close()

      body, _ := ioutil.ReadAll(resp.Body)
      fmt.Println(string(body))
  }
  ```

  ```java Java theme={null}
  import java.net.http.HttpClient;
  import java.net.http.HttpRequest;
  import java.net.http.HttpResponse;
  import java.net.URI;

  public class Main {
      public static void main(String[] args) throws Exception {
          String url = "https://api.apimart.ai/v1/tasks/task-unified-1757156493-imcg5zqt?language=ja";

          HttpClient client = HttpClient.newHttpClient();
          HttpRequest request = HttpRequest.newBuilder()
              .uri(URI.create(url))
              .header("Authorization", "Bearer <token>")
              .GET()
              .build();

          HttpResponse<String> response = client.send(request,
              HttpResponse.BodyHandlers.ofString());

          System.out.println(response.body());
      }
  }
  ```

  ```php PHP theme={null}
  <?php

  $url = "https://api.apimart.ai/v1/tasks/task-unified-1757156493-imcg5zqt?language=ja";

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      "Authorization: Bearer <token>"
  ]);

  $response = curl_exec($ch);
  curl_close($ch);

  echo $response;
  ?>
  ```

  ```ruby Ruby theme={null}
  require 'net/http'
  require 'json'
  require 'uri'

  url = URI("https://api.apimart.ai/v1/tasks/task-unified-1757156493-imcg5zqt?language=ja")

  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true

  request = Net::HTTP::Get.new(url)
  request["Authorization"] = "Bearer <token>"

  response = http.request(request)
  puts response.body
  ```

  ```swift Swift theme={null}
  import Foundation

  let url = URL(string: "https://api.apimart.ai/v1/tasks/task-unified-1757156493-imcg5zqt?language=ja")!

  var request = URLRequest(url: url)
  request.httpMethod = "GET"
  request.setValue("Bearer <token>", forHTTPHeaderField: "Authorization")

  let task = URLSession.shared.dataTask(with: request) { data, response, error in
      if let error = error {
          print("Error: \(error)")
          return
      }
      
      if let data = data, let responseString = String(data: data, encoding: .utf8) {
          print(responseString)
      }
  }

  task.resume()
  ```

  ```csharp C# theme={null}
  using System;
  using System.Net.Http;
  using System.Threading.Tasks;

  class Program
  {
      static async Task Main(string[] args)
      {
          var url = "https://api.apimart.ai/v1/tasks/task-unified-1757156493-imcg5zqt?language=ja";

          using var client = new HttpClient();
          client.DefaultRequestHeaders.Add("Authorization", "Bearer <token>");

          var response = await client.GetAsync(url);
          var result = await response.Content.ReadAsStringAsync();

          Console.WriteLine(result);
      }
  }
  ```

  ```c C theme={null}
  #include <stdio.h>
  #include <curl/curl.h>

  int main(void) {
      CURL *curl;
      CURLcode res;

      curl_global_init(CURL_GLOBAL_DEFAULT);
      curl = curl_easy_init();

      if(curl) {
          const char *url = "https://api.apimart.ai/v1/tasks/task-unified-1757156493-imcg5zqt?language=ja";

          struct curl_slist *headers = NULL;
          headers = curl_slist_append(headers, "Authorization: Bearer <token>");

          curl_easy_setopt(curl, CURLOPT_URL, url);
          curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

          res = curl_easy_perform(curl);

          if(res != CURLE_OK) {
              fprintf(stderr, "curl_easy_perform() failed: %s\n",
                      curl_easy_strerror(res));
          }

          curl_slist_free_all(headers);
          curl_easy_cleanup(curl);
      }

      curl_global_cleanup();
      return 0;
  }
  ```

  ```objectivec Objective-C theme={null}
  #import <Foundation/Foundation.h>

  int main(int argc, const char * argv[]) {
      @autoreleasepool {
          NSURL *url = [NSURL URLWithString:@"https://api.apimart.ai/v1/tasks/task-unified-1757156493-imcg5zqt?language=ja"];
          
          NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
          [request setHTTPMethod:@"GET"];
          [request setValue:@"Bearer <token>" forHTTPHeaderField:@"Authorization"];
          
          NSURLSessionDataTask *task = [[NSURLSession sharedSession] 
              dataTaskWithRequest:request
              completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                  if (error) {
                      NSLog(@"Error: %@", error);
                      return;
                  }
                  NSString *result = [[NSString alloc] initWithData:data 
                                                          encoding:NSUTF8StringEncoding];
                  NSLog(@"%@", result);
              }];
          
          [task resume];
          [[NSRunLoop mainRunLoop] run];
      }
      return 0;
  }
  ```

  ```ocaml OCaml theme={null}
  (* Requires cohttp and yojson libraries *)
  open Lwt
  open Cohttp
  open Cohttp_lwt_unix

  let url = "https://api.apimart.ai/v1/tasks/task-unified-1757156493-imcg5zqt?language=ja"

  let () =
    let headers = Header.init ()
      |> fun h -> Header.add h "Authorization" "Bearer <token>"
    in
    
    let response = Client.get ~headers (Uri.of_string url) >>= fun (resp, body) ->
      body |> Cohttp_lwt.Body.to_string >|= fun body_str ->
      print_endline body_str
    in
    Lwt_main.run response
  ```

  ```dart Dart theme={null}
  import 'package:http/http.dart' as http;

  void main() async {
    final url = Uri.parse('https://api.apimart.ai/v1/tasks/task-unified-1757156493-imcg5zqt?language=ja');
    
    final response = await http.get(
      url,
      headers: {
        'Authorization': 'Bearer <token>',
      },
    );
    
    print(response.body);
  }
  ```

  ```r R theme={null}
  library(httr)

  url <- "https://api.apimart.ai/v1/tasks/task-unified-1757156493-imcg5zqt?language=ja"

  response <- GET(
    url,
    add_headers(
      Authorization = "Bearer <token>"
    )
  )

  cat(content(response, "text"))
  ```
</RequestExample>

<ResponseExample>
  ```json 200 - 画像生成タスク theme={null}
  {
    "code": 200,
    "data": {
      "id": "task_01KA040M0HP1GJWBJYZMKX1XS1",
      "status": "completed",
      "cost": 0.15,
      "credits_cost": 1.5,
      "progress": 100,
      "result": {
        "images": [
          {
            "url": [
              "https://upload.apimart.ai/f/image/9998236911693428-e8d7441f-f7b4-4130-97ad-9ef8a0dde2ce-image_task_01KA0413RT2GGNZJ9GWQ4PXF2F_0.png"
            ],
            "expires_at": 1763174708
          }
        ]
      },
      "created": 1763088289,
      "completed": 1763088308,
      "estimated_time": 60,
      "actual_time": 19
    }
  }
  ```

  ```json 400 theme={null}
  {
    "error": {
      "code": 400,
      "message": "無効なタスクIDです",
      "type": "invalid_request_error"
    }
  }
  ```

  ```json 401 theme={null}
  {
    "error": {
      "code": 401,
      "message": "認証情報が無効です",
      "type": "authentication_error"
    }
  }
  ```

  ```json 402 theme={null}
  {
    "error": {
      "code": 402,
      "message": "残高が不足しています。アカウントにチャージしてください",
      "type": "payment_required"
    }
  }
  ```

  ```json 403 theme={null}
  {
    "error": {
      "code": 403,
      "message": "アクセスが禁止されています。このリソースへのアクセス権限がありません",
      "type": "permission_error"
    }
  }
  ```

  ```json 429 theme={null}
  {
    "error": {
      "code": 429,
      "message": "レート制限を超過しました。後でもう一度お試しください",
      "type": "rate_limit_error"
    }
  }
  ```

  ```json 500 theme={null}
  {
    "error": {
      "code": 500,
      "message": "内部サーバーエラーが発生しました。後でもう一度お試しください",
      "type": "server_error"
    }
  }
  ```

  ```json 502 theme={null}
  {
    "error": {
      "code": 502,
      "message": "不正なゲートウェイです。サーバーが一時的に利用できません",
      "type": "bad_gateway"
    }
  }
  ```
</ResponseExample>

## 認証

<ParamField header="Authorization" type="string" required>
  すべてのAPIエンドポイントにはBearer Token認証が必要です

  APIキーの取得:

  [APIキー管理ページ](https://apimart.ai/keys)にアクセスしてAPIキーを取得してください

  リクエストヘッダーに追加:

  ```
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## パスパラメータ

<ParamField path="task_id" type="string" required>
  生成APIから返されたタスクID
</ParamField>

## クエリパラメータ

<ParamField query="language" type="string">
  レスポンスコンテンツの言語、以下の値をサポート：

  * `zh` - 中国語
  * `en` - 英語
  * `ko` - 韓国語
  * `ja` - 日本語

  デフォルトは英語
</ParamField>

## レスポンス

<ResponseField name="id" type="string">
  一意のタスク識別子
</ResponseField>

<ResponseField name="status" type="string">
  タスクステータスの値:

  * `pending` - 処理待ち
  * `processing` - 処理中
  * `completed` - 正常に完了
  * `failed` - 失敗
  * `cancelled` - ユーザーによってキャンセル
</ResponseField>

<ResponseField name="cost" type="number">
  このタスクに課金された金額
</ResponseField>

<ResponseField name="credits_cost" type="number">
  このタスクに課金されたクレジット
</ResponseField>

<ResponseField name="progress" type="integer">
  タスク進捗率 (0–100)
</ResponseField>

<ResponseField name="result" type="object">
  タスクの結果、ステータスが`completed`の場合のみ返されます

  <Expandable title="プロパティ">
    <ResponseField name="images" type="array">
      生成された画像オブジェクトの配列（画像生成タスクの場合）
    </ResponseField>

    <ResponseField name="videos" type="array">
      生成された動画オブジェクトの配列（動画生成タスクの場合）
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="created" type="integer">
  タスク作成タイムスタンプ
</ResponseField>

<ResponseField name="completed" type="integer">
  タスク完了タイムスタンプ（完了時のみ存在）
</ResponseField>

<ResponseField name="estimated_time" type="integer">
  推定完了時間（秒）
</ResponseField>

<ResponseField name="actual_time" type="integer">
  実際の完了時間（秒）（完了時のみ存在）
</ResponseField>

<ResponseField name="error" type="object">
  エラー詳細（ステータスが`failed`の場合のみ存在）

  <Expandable title="プロパティ">
    <ResponseField name="code" type="integer">
      エラーコード
    </ResponseField>

    <ResponseField name="message" type="string">
      エラーメッセージ
    </ResponseField>

    <ResponseField name="type" type="string">
      エラータイプ
    </ResponseField>
  </Expandable>
</ResponseField>
