Skip to main content
GET
/
v1
/
batches
/
{batch_id}
Retrieve Batch
curl --request GET \
  --url https://api.moonshot.ai/v1/batches/{batch_id} \
  --header 'Authorization: Bearer <token>'
import requests

url = "https://api.moonshot.ai/v1/batches/{batch_id}"

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

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

print(response.text)
const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};

fetch('https://api.moonshot.ai/v1/batches/{batch_id}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.ai/v1/batches/{batch_id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

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

func main() {

url := "https://api.moonshot.ai/v1/batches/{batch_id}"

req, _ := http.NewRequest("GET", url, nil)

req.Header.Add("Authorization", "Bearer <token>")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.get("https://api.moonshot.ai/v1/batches/{batch_id}")
.header("Authorization", "Bearer <token>")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.moonshot.ai/v1/batches/{batch_id}")

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.read_body
{
  "id": "<string>",
  "object": "batch",
  "endpoint": "<string>",
  "input_file_id": "<string>",
  "completion_window": "<string>",
  "created_at": 123,
  "request_counts": {
    "completed": 123,
    "failed": 123,
    "total": 123
  },
  "output_file_id": "<string>",
  "error_file_id": "<string>",
  "in_progress_at": 123,
  "expires_at": 123,
  "finalizing_at": 123,
  "completed_at": 123,
  "failed_at": 123,
  "cancelling_at": 123,
  "cancelled_at": 123,
  "metadata": {}
}
{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}
{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}
{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}
Retrieve the current status, progress statistics, and detailed metadata of a specific batch task. Typically used to poll whether a task has completed after creation.
import os
from openai import OpenAI
from openai.types import Batch

client = OpenAI(
    api_key=os.environ.get("MOONSHOT_API_KEY"),
    base_url=os.environ.get("MOONSHOT_BASE_URL", "https://api.moonshot.ai/v1"),
)

batch: Batch = client.batches.retrieve("your_batch_id")
print(f"Status: {batch.status}")
print(f"Progress: {batch.request_counts.completed}/{batch.request_counts.total}")
curl ${MOONSHOT_BASE_URL:-https://api.moonshot.ai/v1}/batches/your_batch_id \
  -H "Authorization: Bearer $MOONSHOT_API_KEY"
const OpenAI = require("openai");

const client = new OpenAI({
    apiKey: process.env.MOONSHOT_API_KEY,
    baseURL: process.env.MOONSHOT_BASE_URL || "https://api.moonshot.ai/v1",
});

async function main() {
    const batch = await client.batches.retrieve("your_batch_id");
    console.log(`Status: ${batch.status}`);
    console.log(`Progress: ${batch.request_counts.completed}/${batch.request_counts.total}`);
}

main();
FieldTypeDescription
idstringUnique identifier for the batch task
objectstringObject type, always batch
endpointstringRequest endpoint
input_file_idstringInput file ID
completion_windowstringProcessing time window
statusstringCurrent status: validating, failed, in_progress, finalizing, completed, expired, cancelling, cancelled
output_file_idstring | nullOutput file ID for successful results
error_file_idstring | nullError file ID for failed results
created_atintegerCreation timestamp (Unix)
in_progress_atinteger | nullExecution start timestamp (Unix)
expires_atinteger | nullExpiration timestamp (Unix)
finalizing_atinteger | nullResult preparation start timestamp (Unix)
completed_atinteger | nullCompletion timestamp (Unix)
failed_atinteger | nullValidation failure timestamp (Unix)
cancelling_atinteger | nullCancellation request timestamp (Unix)
cancelled_atinteger | nullCancellation completion timestamp (Unix)
request_countsobjectRequest count statistics, containing completed, failed, and total
metadataobject | nullCustom metadata
For complete usage examples and polling scripts, see the Batch API Guide.
When status is completed, output_file_id contains the results file ID. When status is failed, check error_file_id for error details. If the specified batch_id does not exist, the API returns a 404 error (resource_not_found_error).

Authorizations

Authorization
string
header
required

The Authorization header expects a Bearer token. Use an MOONSHOT_API_KEY as the token. This is a server-side secret key. Generate one on the API keys page in your dashboard.

Path Parameters

batch_id
string
required

The ID of the batch task

Response

Batch task details

id
string
required

Unique identifier for the batch task

object
string
required

Object type, always batch

Example:

"batch"

endpoint
string
required

Request endpoint

input_file_id
string
required

Input file ID

completion_window
string
required

Processing time window

status
enum<string>
required

Current status: validating, failed, in_progress, finalizing, completed, expired, cancelling, cancelled

Available options:
validating,
failed,
in_progress,
finalizing,
completed,
expired,
cancelling,
cancelled
created_at
integer
required

Creation timestamp (Unix)

request_counts
object
required
output_file_id
string | null

Output file ID for successful results

error_file_id
string | null

Error file ID for failed results

in_progress_at
integer | null

Execution start timestamp (Unix)

expires_at
integer | null

Expiration timestamp (Unix)

finalizing_at
integer | null

Result preparation start timestamp (Unix)

completed_at
integer | null

Completion timestamp (Unix)

failed_at
integer | null

Validation failure timestamp (Unix)

cancelling_at
integer | null

Cancellation request timestamp (Unix)

cancelled_at
integer | null

Cancellation completion timestamp (Unix)

metadata
object | null

Custom metadata