Skip to content

Batches

Create a batch

bash
curl https://api.fastapi.ai/v1/batches \
  -H "Authorization: Bearer $FAST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input_file_id": "file-abc123",
    "endpoint": "/v1/responses",
    "completion_window": "24h"
  }'
javascript
const res = await fetch("https://api.fastapi.ai/v1/batches", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.FAST_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    input_file_id: "file-abc123",
    endpoint: "/v1/responses",
    completion_window: "24h",
  }),
});

console.log(await res.json());
python
import os
import requests

resp = requests.post(
  'https://api.fastapi.ai/v1/batches',
  headers={
    'Authorization': f"Bearer {os.environ['FAST_API_KEY']}",
    'Content-Type': 'application/json',
  },
  json={
    'input_file_id': 'file-abc123',
    'endpoint': '/v1/responses',
    'completion_window': '24h',
  },
)

print(resp.json())
go
package main

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

func main() {
  payload := map[string]any{
    "input_file_id":    "file-abc123",
    "endpoint":         "/v1/responses",
    "completion_window": "24h",
  }
  b, _ := json.Marshal(payload)

  req, _ := http.NewRequest("POST", "https://api.fastapi.ai/v1/batches", bytes.NewReader(b))
  req.Header.Set("Authorization", "Bearer "+os.Getenv("FAST_API_KEY"))
  req.Header.Set("Content-Type", "application/json")

  resp, err := http.DefaultClient.Do(req)
  if err != nil {
    panic(err)
  }
  defer resp.Body.Close()

  body, _ := io.ReadAll(resp.Body)
  fmt.Println(string(body))
}
java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
  public static void main(String[] args) throws Exception {
    String body = "{\"input_file_id\":\"file-abc123\",\"endpoint\":\"/v1/responses\",\"completion_window\":\"24h\"}";

    HttpRequest req = HttpRequest.newBuilder()
      .uri(URI.create("https://api.fastapi.ai/v1/batches"))
      .header("Authorization", "Bearer " + System.getenv("FAST_API_KEY"))
      .header("Content-Type", "application/json")
      .POST(HttpRequest.BodyPublishers.ofString(body))
      .build();

    HttpResponse<String> resp = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
    System.out.println(resp.body());
  }
}

那年我双手插兜, 让bug稳如老狗