SiliconFlow

创建batch任务

Upload files

POST
/batches
AuthorizationBearer <token>required

Use the following format for authentication: Bearer

In: header

input_file_idstringrequired

The ID of an uploaded file that contains requests for the new batch.

Example"file-jkvytbjtow"
endpointstringrequired

The endpoint to be used for all requests in the batch. Currently /v1/chat/completions is supported.

Example"/v1/chat/completions"
completion_windowstringrequired

The time frame within which the batch should be processed. The maximum value is 24 hours, and the minimum value is 336 hours.

Example"24h"
metadataobject

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, and querying for objects via API or the dashboard.<\br>Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.

replaceobject

Response Body

const body = JSON.stringify({
  "input_file_id": "file-jkvytbjtow",
  "endpoint": "/v1/chat/completions",
  "completion_window": "24h"
})

fetch("https://api.siliconflow.cn/v1/batches", {
  body
})
package main

import (
  "fmt"
  "net/http"
  "io/ioutil"
  "strings"
)

func main() {
  url := "https://api.siliconflow.cn/v1/batches"
  body := strings.NewReader(`{
    "input_file_id": "file-jkvytbjtow",
    "endpoint": "/v1/chat/completions",
    "completion_window": "24h"
  }`)
  req, _ := http.NewRequest("POST", url, body)
  req.Header.Add("Content-Type", "application/json")
  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := ioutil.ReadAll(res.Body)

  fmt.Println(res)
  fmt.Println(string(body))
}
import requests

url = "https://api.siliconflow.cn/v1/batches"
body = {
  "input_file_id": "file-jkvytbjtow",
  "endpoint": "/v1/chat/completions",
  "completion_window": "24h"
}
response = requests.request("POST", url, json = body, headers = {
  "Content-Type": "application/json"
})

print(response.text)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.time.Duration;
import java.net.http.HttpRequest.BodyPublishers;

var body = BodyPublishers.ofString("""{
  "input_file_id": "file-jkvytbjtow",
  "endpoint": "/v1/chat/completions",
  "completion_window": "24h"
}""");
HttpClient client = HttpClient.newBuilder()
  .connectTimeout(Duration.ofSeconds(10))
  .build();

HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
  .uri(URI.create("https://api.siliconflow.cn/v1/batches"))
  .header("Content-Type", "application/json")
  .POST(body)
  .build();

try {
  HttpResponse<String> response = client.send(requestBuilder.build(), BodyHandlers.ofString());
  System.out.println("Status code: " + response.statusCode());
  System.out.println("Response body: " + response.body());
} catch (Exception e) {
  e.printStackTrace();
}
using System;
using System.Net.Http;
using System.Text;

var body = new StringContent("""
{
  "input_file_id": "file-jkvytbjtow",
  "endpoint": "/v1/chat/completions",
  "completion_window": "24h"
}
""", Encoding.UTF8, "application/json");

var client = new HttpClient();
var response = await client.PostAsync("https://api.siliconflow.cn/v1/batches", body);
var responseBody = await response.Content.ReadAsStringAsync();
curl --request POST \
  --url https://api.siliconflow.cn/v1/batches \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "input_file_id": "file-jkvytbjtow",
  "endpoint": "/v1/chat/completions",
  "completion_window": "24h",
  "metadata": {
    "description": "nightly eval job"
  },
  "replace": {
    "model": "deepseek-ai/DeepSeek-V3"
  }
}'
import requests

url = "https://api.siliconflow.cn/v1/batches"

payload = {
    "input_file_id": "file-jkvytbjtow",
    "endpoint": "/v1/chat/completions",
    "completion_window": "24h",
    "metadata": {"description": "nightly eval job"},
    "replace": {"model": "deepseek-ai/DeepSeek-V3"}
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"input_file_id":"file-jkvytbjtow","endpoint":"/v1/chat/completions","completion_window":"24h","metadata":{"description":"nightly eval job"},"replace":{"model":"deepseek-ai/DeepSeek-V3"}}'
};

fetch('https://api.siliconflow.cn/v1/batches', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));      
{
  "id": "batch_rdyqgrcgjg",
  "object": "batch",
  "endpoint": "/v1/chat/completions",
  "errors": null,
  "input_file_id": "file-jkvytbjtow",
  "completion_window": "24h",
  "status": "in_queue",
  "output_file_id": null,
  "error_file_id": null,
  "created_at": 1741685413,
  "in_progress_at": null,
  "expires_at": 1741771813,
  "finalizing_at": null,
  "completed_at": null,
  "failed_at": null,
  "expired_at": null,
  "cancelling_at": null,
  "cancelled_at": null,
  "request_counts": null,
  "metadata": {
    "description": "nightly eval job"
  }
}
{
  "code": 20012,
  "message": "string",
  "data": "string"
}
"Invalid token"
"Forbidden"
"404 page not found"
{
  "code": 50505,
  "message": "Model service overloaded. Please try again later.",
  "data": "string"
}
"string"