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 Batch
Retrieve the status and details of a specific batch task.
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>"
}
}Usage Example
Usage Example
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();
Response Fields
Response Fields
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the batch task |
object | string | Object type, always batch |
endpoint | string | Request endpoint |
input_file_id | string | Input file ID |
completion_window | string | Processing time window |
status | string | Current status: validating, failed, in_progress, finalizing, completed, expired, cancelling, cancelled |
output_file_id | string | null | Output file ID for successful results |
error_file_id | string | null | Error file ID for failed results |
created_at | integer | Creation timestamp (Unix) |
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) |
request_counts | object | Request count statistics, containing completed, failed, and total |
metadata | object | null | Custom metadata |
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
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
The ID of the batch task
Response
Batch task details
Unique identifier for the batch task
Object type, always batch
"batch"
Request endpoint
Input file ID
Processing time window
Current status: validating, failed, in_progress, finalizing, completed, expired, cancelling, cancelled
validating, failed, in_progress, finalizing, completed, expired, cancelling, cancelled Creation timestamp (Unix)
Show child attributes
Show child attributes
Output file ID for successful results
Error file ID for failed results
Execution start timestamp (Unix)
Expiration timestamp (Unix)
Result preparation start timestamp (Unix)
Completion timestamp (Unix)
Validation failure timestamp (Unix)
Cancellation request timestamp (Unix)
Cancellation completion timestamp (Unix)
Custom metadata
Show child attributes
Show child attributes
Was this page helpful?