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

# Create a batch

> Creates a batch from an uploaded input file. The batch starts in
`validating`. Send an `Idempotency-Key` header to make retries safe: a
repeat with the same key returns the original batch.
`output_expires_after` is not supported and is rejected with a 400;
output and error files are kept 30 days.




## OpenAPI

````yaml post /v1/batches
openapi: 3.1.0
info:
  title: Perplexity AI API
  description: Perplexity AI API
  version: 1.0.0
servers:
  - url: https://api.perplexity.ai
    description: Perplexity AI API
security: []
paths:
  /v1/batches:
    post:
      tags:
        - Batches
      summary: Create a batch
      description: |
        Creates a batch from an uploaded input file. The batch starts in
        `validating`. Send an `Idempotency-Key` header to make retries safe: a
        repeat with the same key returns the original batch.
        `output_expires_after` is not supported and is rejected with a 400;
        output and error files are kept 30 days.
      operationId: createBatch
      parameters:
        - $ref: '#/components/parameters/BatchIdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateBatchRequest'
      responses:
        '200':
          description: The created batch
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Batch'
        '400':
          description: Invalid request, input file, or reused idempotency key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
        '402':
          description: API credits exhausted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
        '403':
          description: Batch is not available to organizations with zero data retention
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
        '503':
          description: Batch service unavailable; retry
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
      security:
        - HTTPBearer: []
components:
  parameters:
    BatchIdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      schema:
        type: string
        maxLength: 200
      description: Unique key for this create; a repeat returns the original batch
  schemas:
    CreateBatchRequest:
      type: object
      required:
        - input_file_id
        - endpoint
      properties:
        input_file_id:
          type: string
          description: Id of a file uploaded with `purpose=batch`
        endpoint:
          type: string
          enum:
            - /v1/responses
          description: Endpoint every line in the input file targets
        completion_window:
          type: string
          enum:
            - 24h
          description: Target completion time; `24h` is the only value and the default
        metadata:
          type: object
          nullable: true
          additionalProperties:
            type: string
          description: Up to 16 key value pairs; keys up to 64 characters, values up to 512
    Batch:
      type: object
      required:
        - id
        - object
        - endpoint
        - input_file_id
        - completion_window
        - status
        - created_at
        - request_counts
        - usage
      properties:
        id:
          type: string
        object:
          type: string
          enum:
            - batch
        endpoint:
          type: string
        errors:
          allOf:
            - $ref: '#/components/schemas/BatchErrors'
          nullable: true
        input_file_id:
          type: string
        completion_window:
          type: string
        status:
          $ref: '#/components/schemas/BatchStatus'
        output_file_id:
          type: string
          nullable: true
        error_file_id:
          type: string
          nullable: true
        created_at:
          type: integer
          format: int64
          description: Unix seconds
        in_progress_at:
          type: integer
          format: int64
          nullable: true
        expires_at:
          type: integer
          format: int64
          nullable: true
        finalizing_at:
          type: integer
          format: int64
          nullable: true
        completed_at:
          type: integer
          format: int64
          nullable: true
        failed_at:
          type: integer
          format: int64
          nullable: true
        expired_at:
          type: integer
          format: int64
          nullable: true
        cancelling_at:
          type: integer
          format: int64
          nullable: true
        cancelled_at:
          type: integer
          format: int64
          nullable: true
        request_counts:
          $ref: '#/components/schemas/BatchRequestCounts'
        usage:
          $ref: '#/components/schemas/BatchUsage'
        metadata:
          type: object
          nullable: true
          additionalProperties:
            type: string
    ApiError:
      type: object
      properties:
        error:
          type: object
          required:
            - message
            - type
            - code
          properties:
            message:
              description: Human-readable error message
              type: string
            type:
              type: string
              description: Error type identifier
            code:
              type: integer
              description: HTTP status code
            param:
              type: string
              description: Parameter that caused the error
              nullable: true
    BatchErrors:
      type: object
      required:
        - object
        - data
      properties:
        object:
          type: string
          enum:
            - list
        data:
          type: array
          items:
            $ref: '#/components/schemas/BatchError'
    BatchStatus:
      type: string
      enum:
        - validating
        - in_progress
        - finalizing
        - completed
        - expired
        - cancelling
        - cancelled
        - failed
    BatchRequestCounts:
      type: object
      required:
        - total
        - completed
        - failed
      properties:
        total:
          format: int64
          type: integer
        completed:
          format: int64
          type: integer
        failed:
          format: int64
          type: integer
    BatchUsage:
      type: object
      required:
        - input_tokens
        - input_tokens_details
        - output_tokens
        - output_tokens_details
        - total_tokens
      properties:
        input_tokens:
          format: int64
          type: integer
        input_tokens_details:
          type: object
          required:
            - cached_tokens
          properties:
            cached_tokens:
              format: int64
              type: integer
        output_tokens:
          format: int64
          type: integer
        output_tokens_details:
          type: object
          required:
            - reasoning_tokens
          properties:
            reasoning_tokens:
              format: int64
              type: integer
        total_tokens:
          format: int64
          type: integer
    BatchError:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
        message:
          type: string
        line:
          type: integer
          format: int64
          nullable: true
          description: 1-based input line the error refers to
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````