Batch API


📖 What is Batch API?

The Batch API allows you to process multiple AI requests in a single batch operation, which is cost-effective and efficient for large-volume processing. Instead of making individual API calls, you submit multiple messages at once, and the system processes them asynchronously. Once completed, the results are sent to your specified webhook URL.

Best suited for non-time-sensitive, high-volume operations.

Perfect for:

  • Bulk content generation

  • Data processing

  • Translations

  • Summarizations

  • Any large-scale AI workflows


🔗 API Endpoint

POST <https://api.gtwy.ai/api/v2/model/batch/chat/completion>


📋 Request Parameters

Required Headers

Header

Value

Description

pauthkey

Your pauthkey

content-type

application/json

Request content type


Request Body

Parameter

Type

Required

Description

webhook

Object

Yes

Webhook configuration

webhook.url

String

Yes

URL to receive batch results

webhook.headers

Object

No

Custom webhook headers

batch

Array[String]

Yes

Messages to process

bridge_id

String

Yes

Bridge / configuration ID

batch_variables

Array[Object]

No

Metadata for response mapping

⚠️ Important:

If batch_variables is provided, its length must exactly match the batch array length.


💻 Example Request

curl --location '<https://api.gtwy.ai/api/v2/model/batch/chat/completion>' \\
--header 'pauthkey': 'YOUR_PAUTH_KEY' \\
--header 'content-type: application/json' \\
--data '{
  "webhook": {
    "url": "<https://your-webhook-url.com/endpoint>",
    "headers": {}
  },
  "batch": [
    "hi my name is husain",
    "hi my name is harsh"
  ],
  "bridge_id": "68b6ef6f4623c70889b02ebd",
  "batch_variables": [
    {
      "name": "husain"
    },
    {
      "name": "harsh"
    }
  ]
}'


💡 Tip: Always store batch_id and custom_id for tracking and debugging.


📬 Webhook Response

Webhook is triggered once after all batch items are processed (within 24 hours).

Example Webhook Payload

[
  {
    "data": {
      "id": "chatcmpl-CnKGinzA17Zo15BvFqMLP9WvydoGp",
      "content": "Hi Husain! How can I assist you today?",
      "model": "gpt-4o-mini-2024-07-18",
      "role": "assistant",
      "finish_reason": "completed"
    },
    "usage": {
      "input_tokens": 35,
      "output_tokens": 9,
      "total_tokens": 44
    },
    "batch_id": "batch_694112f91a7c8190b388404757b50f40",
    "custom_id": "a3d8f7b2-4c1e-4a9f-9b5d-7e2c8f1a4d6b",
    "variables": {
      "name": "husain"
    }
  }
]

🎯 Using batch_variables

Attach metadata to each request for accurate response mapping.

Rules

  1. Must match batch length

  2. Index-based mapping

  3. Any valid JSON

  4. Returned unchanged in webhook