microsoft-foundry.rest.security.o-auth2-auth
Batch
List batches
GET
/openai/v1/batches
Lists batches matching the request filters.
Query parameters
after
string
A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
limit
integer
A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
Responses
The request has succeeded.
Body
Content-Type: application/json
data
OpenAI.Batch[]
required
first_id
string
last_id
string
has_more
boolean
required
object
enum
required
list
Request
curl https://api.openai.com/v1/batches?limit=2 \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json"
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
page = client.batches.list()
page = page.data[0]
print(page.id)
import OpenAI from "openai";
const openai = new OpenAI();
async function main() {
const list = await openai.batches.list();
for await (const batch of list) {
console.log(batch);
}
}
main();
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
});
// Automatically fetches more pages as needed.
for await (const batch of client.batches.list()) {
console.log(batch.id);
}
package main
import (
"context"
"fmt"
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
func main() {
client := openai.NewClient(
option.WithAPIKey("My API Key"),
)
page, err := client.Batches.List(context.TODO(), openai.BatchListParams{})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v
", page)
}
package com.openai.example;
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.batches.BatchListPage;
import com.openai.models.batches.BatchListParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
BatchListPage page = client.batches().list();
}
}
require "openai"
openai = OpenAI::Client.new(api_key: "My API Key")
page = openai.batches.list
puts(page)
Response
{
"object": "list",
"data": [
{
"id": "batch_abc123",
"object": "batch",
"endpoint": "/v1/chat/completions",
"errors": null,
"input_file_id": "file-abc123",
"completion_window": "24h",
"status": "completed",
"output_file_id": "file-cvaTdG",
"error_file_id": "file-HOWS94",
"created_at": 1711471533,
"in_progress_at": 1711471538,
"expires_at": 1711557933,
"finalizing_at": 1711493133,
"completed_at": 1711493163,
"failed_at": null,
"expired_at": null,
"cancelling_at": null,
"cancelled_at": null,
"request_counts": {
"total": 100,
"completed": 95,
"failed": 5
},
"metadata": {
"customer_id": "user_123456789",
"batch_description": "Nightly job",
}
},
{ ... },
],
"first_id": "batch_abc123",
"last_id": "batch_abc456",
"has_more": true
}