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

# Create a Batch

> Create a new [Batch](/core-resources/batch) for organizing tasks.

<Accordion title="Authentication" icon="key">
  Every request sent to Scale's API requires authentication. In short, your API Key is the Bearer token. See the [Authentication](/get-started/authentication) section for more details.
</Accordion>

<Tip>
  ### Required request parameters

  You must provide:

  * **Name** (`name`) - The name for the batch
  * **Project** (`project`) - Project ID or project name to associate with the batch
</Tip>


## OpenAPI

````yaml POST /v2/batch
openapi: 3.1.0
info:
  title: GenAI API Spec
  description: 'Data Engine: Generative AI API Specification'
  version: 0.0.1
servers:
  - url: https://api.scale.com
security:
  - bearerAuth: []
  - basicAuth: []
paths:
  /v2/batch:
    post:
      tags:
        - v2
      summary: Create a Batch
      description: Create a new [Batch](/core-resources/batch) for organizing tasks.
      operationId: createBatch
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
              properties:
                name:
                  $ref: '#/components/schemas/BatchName'
                project_id:
                  $ref: '#/components/schemas/ProjectId'
                project_name:
                  $ref: '#/components/schemas/ProjectName'
                callback:
                  $ref: '#/components/schemas/Callback'
                staging_batch:
                  type: boolean
                  description: Whether this is a staging batch.
                  default: false
                metadata:
                  $ref: '#/components/schemas/BatchMetadata'
            examples:
              Basic Batch:
                value:
                  name: My New Batch
                  project: project_123
              Batch with Metadata:
                value:
                  name: Training Batch
                  project: My Project
                  callback: https://example.com/callback
                  staging_batch: true
                  metadata:
                    priority: high
                    dataset_version: v1.2
      responses:
        '200':
          description: Batch created successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Batch'
              examples:
                Created Batch:
                  $ref: '#/components/examples/SampleBatch'
        '500':
          description: Error response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status_code:
                    type: number
                    example: 500
                  error:
                    type: string
                    example: An error has occurred.
      x-codeSamples:
        - lang: bash
          label: cURL
          source: |
            API_KEY='live_...'
            curl --request POST \
                --url "https://api.scale.com/v2/batch" \
                --header "Authorization: Bearer $API_KEY" \
                --header "Content-Type: application/json" \
                --data '{
                  "name": "My New Batch",
                  "project": "project_123"
                }'
        - lang: python
          label: Python SDK
          source: |
            import scaleapi

            API_KEY = 'live_...'
            client = scaleapi.ScaleClient(API_KEY)

            response = client.v2.create_batch(
              name="My New Batch",
              project="project_123"
            )
            print(response.to_json())
        - lang: python
          label: Python
          source: |
            import requests

            API_KEY = 'live_...'

            response = requests.request(
              "POST",
              url="https://api.scale.com/v2/batch",
              json={
                "name": "My New Batch",
                "project": "project_123"
              },
              headers={
                "Accept": "application/json",
                "Authorization": f"Bearer {API_KEY}",
                "Content-Type": "application/json",
              },
            )
            print(response.json())
        - lang: javascript
          label: JavaScript
          source: |
            const API_KEY = 'live_...';

            const response = await fetch('https://api.scale.com/v2/batch', {
              method: 'POST',
              headers: {
                Accept: 'application/json',
                Authorization: `Bearer ${API_KEY}`,
                'Content-Type': 'application/json',
              },
              body: JSON.stringify({
                name: 'My New Batch',
                project: 'project_123'
              }),
            });
            console.log(await response.json());
        - lang: go
          label: Go
          source: |
            package main

            import (
              "bytes"
              "encoding/json"
              "fmt"
              "io/ioutil"
              "net/http"
            )

            func main() {
              apiKey := "live_..."

              requestBody := map[string]string{
                "name": "My New Batch",
                "project": "project_123",
              }
              jsonData, _ := json.Marshal(requestBody)

              req, _ := http.NewRequest("POST", "https://api.scale.com/v2/batch", bytes.NewBuffer(jsonData))

              req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", apiKey))
              req.Header.Add("Content-Type", "application/json")

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

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

              fmt.Println(string(body))
            }
        - lang: java
          label: Java
          source: |
            package com.scale.api;

            import kong.unirest.HttpResponse;
            import kong.unirest.Unirest;

            public class App {
                public static void main(String[] args) {
                    String apiKey = "live_...";

                    String requestBody = "{\"name\": \"My New Batch\", \"project\": \"project_123\"}";

                    HttpResponse<String> response = Unirest.post("https://api.scale.com/v2/batch")
                      .header("Authorization", String.format("Bearer %s", apiKey))
                      .header("Content-Type", "application/json")
                      .body(requestBody)
                      .asString();

                    System.out.println(response.getBody());
                }
            }
components:
  schemas:
    BatchName:
      type: string
      description: The name of the batch.
      example: My Scale Batch
    ProjectId:
      type: string
      description: A unique identifier for the project.
      example: project_abc123
    ProjectName:
      type: string
      description: The name of the project.
      example: My Scale Project
    Callback:
      type: string
      description: Callback URL or email for the entity upon completion.
      example: https://example.com/callback
    BatchMetadata:
      $ref: '#/components/schemas/Metadata'
    Batch:
      type: object
      required:
        - id
        - name
        - project
        - created_at
        - status
        - metadata
      properties:
        id:
          $ref: '#/components/schemas/BatchId'
        name:
          $ref: '#/components/schemas/BatchName'
        project:
          $ref: '#/components/schemas/ExpandableProject'
          description: >-
            Project ID or [Project](/core-resources/project) associated with the
            batch.
        created_at:
          $ref: '#/components/schemas/DateString'
        completed_at:
          $ref: '#/components/schemas/DateString'
          description: UTC timestamp when the batch was completed.
        status:
          $ref: '#/components/schemas/BatchStatus'
        callback:
          $ref: '#/components/schemas/Callback'
        metadata:
          $ref: '#/components/schemas/BatchMetadata'
    Metadata:
      type: object
      description: Custom metadata for the entity.
      additionalProperties: true
      default: {}
    BatchId:
      type: string
      description: A unique identifier for the batch.
      example: batch_abc123
    ExpandableProject:
      description: >-
        Project ID or [Project](/core-resources/project) associated with the
        task.
      oneOf:
        - $ref: '#/components/schemas/ProjectId'
        - $ref: '#/components/schemas/Project'
    DateString:
      type: string
      format: date-time
      description: A timestamp formatted as an ISO 8601 date-time string.
    BatchStatus:
      type: string
      enum:
        - staging
        - in_progress
        - completed
        - paused
        - cancelled
      description: Status of the batch.
    Project:
      type: object
      required:
        - id
        - name
        - created_at
      properties:
        id:
          $ref: '#/components/schemas/ProjectId'
          description: Unique identifier for the project
        name:
          $ref: '#/components/schemas/ProjectName'
        created_at:
          $ref: '#/components/schemas/DateString'
        types:
          type: array
          description: List of project types associated with the project.
          items:
            $ref: '#/components/schemas/GenAIProjectType'
          example:
            - 'RLHF: Pref Ranking'
        models:
          type: array
          description: List of models associated with the project.
          items:
            $ref: '#/components/schemas/Model'
          example:
            - gpt-4
            - my-model-123
    GenAIProjectType:
      type: string
      enum:
        - SFT
        - 'RLHF: Pref Ranking'
        - 'RLHF: Pref Ranking with Rewrites'
        - 'RLVR: Reinforcement Learning with Verifiable Rewards'
        - Rubrics
        - Process Supervision
        - Evals
        - Prompt Generation
        - Content Understanding
        - Other
    Model:
      type: string
      description: The name of the model that generated the message.
      example: my-model-123
  examples:
    SampleBatch:
      value:
        id: batch_123
        name: Batch Name Example
        project: project_123
        created_at: '2022-07-25T07:32:34.318Z'
        status: completed
        callback: https://example.com/callback
        metadata: {}
        completed_at: '2022-07-26T07:32:34.318Z'
  securitySchemes:
    bearerAuth:
      description: >-
        Your API Key is the Bearer token. See the
        [Authentication](/get-started/authentication) section to learn how to
        access your key.
      type: http
      scheme: bearer
    basicAuth:
      description: >-
        Basic HTTP Authentication. Your API Key is your username.  Learn more
        about setting up Authentication [here](/get-started/authentication).
      type: http
      scheme: basic

````