创建批处理

示例用法

import OpenAI from 'openai';
import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai'

const client = new OpenAI({
  baseURL: PORTKEY_GATEWAY_URL,
  defaultHeaders: createHeaders({
    apiKey: "PORTKEY_API_KEY",
    virtualKey: "PROVIDER_VIRTUAL_KEY"
  })
});

async function main() {
  const batch = await client.batches.create({
    input_file_id: "file-abc123",
    endpoint: "/v1/chat/completions",
    completion_window: "24h"
  });

  console.log(batch);
}

main();

Creates and executes a batch from an uploaded file of requests

post
/batches
Authorizations
x-portkey-api-keystringRequired
x-portkey-virtual-keystringRequired
Body
or
or
or
Responses
chevron-right
200

Batch created successfully.

application/json
idstringRequired
objectstring · enumRequired

The object type, which is always batch.

Possible values:
endpointstringRequired

The Portkey API endpoint used by the batch.

input_file_idstringRequired

The ID of the input file for the batch.

completion_windowstringRequired

The time frame within which the batch should be processed.

statusstring · enumRequired

The current status of the batch.

Possible values:
output_file_idstringOptional

The ID of the file containing the outputs of successfully executed requests.

error_file_idstringOptional

The ID of the file containing the outputs of requests with errors.

created_atintegerRequired

The Unix timestamp (in seconds) for when the batch was created.

in_progress_atintegerOptional

The Unix timestamp (in seconds) for when the batch started processing.

expires_atintegerOptional

The Unix timestamp (in seconds) for when the batch will expire.

finalizing_atintegerOptional

The Unix timestamp (in seconds) for when the batch started finalizing.

completed_atintegerOptional

The Unix timestamp (in seconds) for when the batch was completed.

failed_atintegerOptional

The Unix timestamp (in seconds) for when the batch failed.

expired_atintegerOptional

The Unix timestamp (in seconds) for when the batch expired.

cancelling_atintegerOptional

The Unix timestamp (in seconds) for when the batch started cancelling.

cancelled_atintegerOptional

The Unix timestamp (in seconds) for when the batch was cancelled.

metadataobject · nullableOptional

Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long.

post
/batches
200

Batch created successfully.

Last updated