Skip to content

types: Missing type for batch request input and output objects #1937

Closed as duplicate

Description

@alugowski

Confirm this is a feature request for the Python library and not the underlying OpenAI API.

  • This is a feature request for the Python library

Describe the feature or improvement you're requesting

Batch input files are a list of up to 50,000 request input objects, where each one looks like this:

{"custom_id": "request-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "gpt-4o-mini", "messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is 2+2?"}]}}

https://platform.openai.com/docs/api-reference/batch/request-input

I don't see this anywhere in openai.types. It should be there to make it easier to use batches.

Same for the output object, https://platform.openai.com/docs/api-reference/batch/request-output

Additional context

AFAIK the body element's type is Union[EmbeddingCreateParams, CompletionCreateParams]

Activity

  1. changed the title [-]Missing type for batch request input and output objects[/-] [+]types: Missing type for batch request input and output objects[/+] on Dec 11, 2024
  2. shea-parkes commented on Nov 16, 2025

    @shea-parkes

    Yea, this caught me very off guard today. I did do the "thumbs up" thing, but it was surprising enough I went ahead and dropped a comment here as well. Not sure how this got missed...

    Similar to the hint above, the body of the response is openai.types.Completion, but still have to manually define the other parts.

  3. NikkiAung commented on Dec 30, 2025

    @NikkiAung

    For batch_request_input.py with TypedDict class, in accordance with Batch API current supporting available endpoints docu, I will be adding custom_id, method (forcing with exactly the string "POST") using Literal, url, and body wrapping with BatchRequestBody using Union with current supporting things like below while adding fallback for any additional types

    BatchRequestBody = Union[
        ChatCompletionCreateParams,
        CompletionCreateParams,
        EmbeddingCreateParams,
        ModerationCreateParams,
        ResponseCreateParams,
        Dict[str, Any],  # Fallback for any additional types
    ]
    
    Image

    On one hand, for batch_request_output.py with BaseModel class, I'm pretty sure there should be id, custom_id, response wrapping with BatchRequestOutputResponse using Union with current supporting things, including @shea-parkes mentioned Completion like below

    # Note I used Union of specific response types since it's better than falling back to Dict[str, Any].
    BatchResponseBody = Union[
        ChatCompletion,
        Completion,
        CreateEmbeddingResponse,
        ModerationCreateResponse,
        Response,
    ]
    

    and error wrapping with BatchRequestOutputError with current supporting things like code (Literal["batch_expired", "batch_cancelled", "request_timeout"]) and message referring to this document

    Image

    If anyone is interested in trying this feature early using this git branch, your feedback would be greatly appreciated, @RobertCraigie, @alugowski, & @shea-parkes.! :))

  4. marcuswood-oai commented on Sep 15, 2026

    @marcuswood-oai
    Contributor

    Thanks for raising this, and thanks to everyone who contributed proposed types. The missing Batch JSONL record types need to be defined in the shared schema and exposed through SDK generation. openai/openai-openapi#578 tracks that work and links back to your report.

    In the meantime, the Batch guide describes the record format and how to match results using custom_id. That provides a way to work with the files while the envelope types are missing. We’re closing this report to keep the work together in openai/openai-openapi#578; please follow that issue for the schema and SDK updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions