Gemini Batch Task cannot be deleted/cancelled

I am using the same BATCH_NAME to query/delete/cancel. Querying works normally, but deleting/cancelling results in a 400 error.

echo $BATCH_NAME                        
batches/01fzn77cxwy1xyrq9zvr8uthc2flk8dt55j7
curl https://generativelanguage.googleapis.com/v1beta/$BATCH_NAME \       
-H "x-goog-api-key: $GEMINI_API_KEY"
{
  "name": "batches/01fzn77cxwy1xyrq9zvr8uthc2flk8dt55j7",
  "metadata": {
    "@type": "type.googleapis.com/google.ai.generativelanguage.v1main.GenerateContentBatch",
    "model": "models/gemini-2.5-flash",
    "displayName": "my-batch-requests",
    "createTime": "2025-08-13T06:52:44.322831654Z",
    "updateTime": "2025-08-13T06:52:44.322831654Z",
    "batchStats": {
      "requestCount": "2",
      "pendingRequestCount": "2"
    },
    "state": "BATCH_STATE_PENDING",
    "name": "batches/01fzn77cxwy1xyrq9zvr8uthc2flk8dt55j7"
  }
}
curl https://generativelanguage.googleapis.com/v1beta/$BATCH_NAME:cancel \
-H "x-goog-api-key: $GEMINI_API_KEY"
{
  "error": {
    "code": 400,
    "message": "Could not parse the batch name",
    "status": "INVALID_ARGUMENT"
  }
}

curl https://generativelanguage.googleapis.com/v1beta/$BATCH_NAME:delete \        
-H "x-goog-api-key: $GEMINI_API_KEY"                            
{
  "error": {
    "code": 400,
    "message": "Could not parse the batch name",
    "status": "INVALID_ARGUMENT"
  }
}

Hi @gaa_da,

The actual issue isn’t with the batch name itself but with the HTTP method you are using for the cancel and delete operations.

The cancel operation is a custom method on the batch resource. According to the API specification, custom methods must be invoked using the POST HTTP method.

Correct method to Cancel

curl -X POST "https://generativelanguage.googleapis.com/v1beta/$BATCH_NAME:cancel" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'

Hope this helps