Files & Batches
File Operations
Section titled “File Operations”Upload, retrieve, list, and delete files. Files are used with batch processing, fine-tuning, and assistants.
Upload a File
Section titled “Upload a File”Upload a file for use with the API
import asyncioimport osfrom liter_llm import create_clientfrom liter_llm._internal_bindings import CreateFileRequest
async def main() -> None: client = create_client(api_key=os.environ["API_KEY"]) req = CreateFileRequest.from_json("{\"file\":\"eyJwcm9tcHQiOiAiaGVsbG8ifQo=\",\"filename\":\"training_data.jsonl\",\"purpose\":\"fine-tune\"}") result = await client.create_file(req) print(result.id)
asyncio.run(main())Upload a file for use with the API
import { FilePurpose, createClient } from "@xberg-io/liter-llm";async function main() { const client = createClient("your-api-key"); const result = await client.createFile({ file: "eyJwcm9tcHQiOiAiaGVsbG8ifQo=", filename: "training_data.jsonl", purpose: FilePurpose.FineTune }); console.log(result.id);}
void main();Upload a file for use with the API
use liter_llm::BatchClient;use liter_llm::FileClient;use liter_llm::LlmClient;use liter_llm::ResponseClient;
#[tokio::main]async fn main() { let req_json: serde_json::Value = serde_json::from_str(r#"{"file":"eyJwcm9tcHQiOiAiaGVsbG8ifQo=","filename":"training_data.jsonl","purpose":"fine-tune"}"#).unwrap(); let req = serde_json::from_value(req_json).unwrap(); let client = liter_llm::create_client(std::env::var("API_KEY").expect("API_KEY must be set"), None, None, None, None).unwrap(); let result = client.create_file(req).await.expect("call failed"); println!("{:?}", result.id);}Upload a file for use with the API
package main
import ( "fmt" pkg "github.com/xberg-io/liter-llm/packages/go/v2")
func ptr[T any](value T) *T { return &value }func main() { req := pkg.CreateFileRequest{ File: `eyJwcm9tcHQiOiAiaGVsbG8ifQo=`, Purpose: pkg.FilePurposeFineTune, Filename: ptr(`training_data.jsonl`), } client, clientErr := pkg.CreateClient("your-api-key", nil, nil, nil, nil) if clientErr != nil { panic(clientErr) } defer client.Free() result, err := client.CreateFile(req) if err != nil { panic(err) } fmt.Printf("%+v\n", result.ID)}Upload a file for use with the API
import io.xberg.literllm.*;
public final class Example { public static void main(String[] args) throws Exception { var reqJson = "{\"file\":\"eyJwcm9tcHQiOiAiaGVsbG8ifQo=\",\"filename\":\"training_data.jsonl\",\"purpose\":\"fine-tune\"}"; var req = JsonUtil.fromJson(reqJson, CreateFileRequest.class); var apiKey = System.getenv("API_KEY"); if (apiKey == null || apiKey.isEmpty()) throw new IllegalStateException("API_KEY must be set"); try (var client = LiterLlm.createClient(apiKey, null, null, null, null)) { var result = client.createFile(req); System.out.println(result.id()); } }}Upload a file for use with the API
using System;using System.Text.Json;using LiterLlm;
var ConfigOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };var apiKey = Environment.GetEnvironmentVariable("API_KEY") ?? throw new InvalidOperationException("API_KEY must be set"); using var client = LiterLlmConverter.CreateClient(apiKey, null, null, null, null);var result = await client.CreateFileAsync(new CreateFileRequest { File = "eyJwcm9tcHQiOiAiaGVsbG8ifQo=", Filename = "training_data.jsonl", Purpose = JsonSerializer.Deserialize<FilePurpose>("\"fine-tune\"", ConfigOptions)! });Console.WriteLine(result.Id);Upload a file for use with the API
require "liter_llm"result = LiterLlm.create_file(LiterLlm::CreateFileRequest.new(file: 'eyJwcm9tcHQiOiAiaGVsbG8ifQo=', filename: 'training_data.jsonl', purpose: 'fine-tune'))puts result.id.inspectUpload a file for use with the API
<?php
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use Liter\Llm\LiterLlm;use Liter\Llm\CreateFileRequest;$req = \Liter\Llm\CreateFileRequest::from_json(json_encode(["file" => "eyJwcm9tcHQiOiAiaGVsbG8ifQo=", "filename" => "training_data.jsonl", "purpose" => "fine-tune"]));$result = LiterLlm::createFile($req);var_dump($result->id);Upload a file for use with the API
api_key = System.fetch_env!("API_KEY"){:ok, client} = LiterLlm.create_client(api_key)result = LiterLlm.defaultclient_create_file_async(client, "{\"file\":\"eyJwcm9tcHQiOiAiaGVsbG8ifQo=\",\"filename\":\"training_data.jsonl\",\"purpose\":\"fine-tune\"}")IO.inspect(result.id)Upload a file for use with the API
import { WasmCreateFileRequest, WasmFilePurpose, createClient } from "@xberg-io/liter-llm-wasm";async function main() { const req: WasmCreateFileRequest = (() => { const _u0 = WasmCreateFileRequest.default(); _u0.file = "eyJwcm9tcHQiOiAiaGVsbG8ifQo="; _u0.filename = "training_data.jsonl"; _u0.purpose = WasmFilePurpose.FineTune; return _u0; })(); const client = createClient("your-api-key"); try { const result = await client.createFile(req); console.log(result.id); } finally { client.free(); }}
void main();File Methods
Section titled “File Methods”| Method | Description |
|---|---|
create_file |
Upload a file with a purpose ("batch", "fine-tune", "assistants") |
retrieve_file |
Get metadata for an uploaded file by ID |
delete_file |
Delete an uploaded file by ID |
list_files |
List all uploaded files, optionally filtered by purpose |
file_content |
Download the raw content of an uploaded file |
Batch Processing
Section titled “Batch Processing”Create batch jobs to process multiple requests asynchronously at reduced cost:
Create a new batch processing job
import asyncioimport osfrom liter_llm import create_clientfrom liter_llm._internal_bindings import CreateBatchRequest
async def main() -> None: client = create_client(api_key=os.environ["API_KEY"]) req = CreateBatchRequest.from_json("{\"completion_window\":\"24h\",\"endpoint\":\"/v1/chat/completions\",\"input_file_id\":\"file-abc123\"}") result = await client.create_batch(req) print(result.id) print(result.status)
asyncio.run(main())Create a new batch processing job
import { createClient } from "@xberg-io/liter-llm";async function main() { const client = createClient("your-api-key"); const result = await client.createBatch({ completionWindow: "24h", endpoint: "/v1/chat/completions", inputFileId: "file-abc123" }); console.log(result.id); console.log(result.status);}
void main();Create a new batch processing job
use liter_llm::BatchClient;use liter_llm::FileClient;use liter_llm::LlmClient;use liter_llm::ResponseClient;
#[tokio::main]async fn main() { let req_json: serde_json::Value = serde_json::from_str(r#"{"completion_window":"24h","endpoint":"/v1/chat/completions","input_file_id":"file-abc123"}"#).unwrap(); let req = serde_json::from_value(req_json).unwrap(); let client = liter_llm::create_client(std::env::var("API_KEY").expect("API_KEY must be set"), None, None, None, None).unwrap(); let result = client.create_batch(req).await.expect("call failed"); println!("{:?}", result.id); println!("{:?}", result.status);}Create a new batch processing job
package main
import ( "fmt" pkg "github.com/xberg-io/liter-llm/packages/go/v2")
func main() { req := pkg.CreateBatchRequest{ InputFileID: `file-abc123`, Endpoint: `/v1/chat/completions`, CompletionWindow: `24h`, } client, clientErr := pkg.CreateClient("your-api-key", nil, nil, nil, nil) if clientErr != nil { panic(clientErr) } defer client.Free() result, err := client.CreateBatch(req) if err != nil { panic(err) } fmt.Printf("%+v\n", result.ID) fmt.Printf("%+v\n", result.Status)}Create a new batch processing job
import io.xberg.literllm.*;
public final class Example { public static void main(String[] args) throws Exception { var reqJson = "{\"completion_window\":\"24h\",\"endpoint\":\"/v1/chat/completions\",\"input_file_id\":\"file-abc123\"}"; var req = JsonUtil.fromJson(reqJson, CreateBatchRequest.class); var apiKey = System.getenv("API_KEY"); if (apiKey == null || apiKey.isEmpty()) throw new IllegalStateException("API_KEY must be set"); try (var client = LiterLlm.createClient(apiKey, null, null, null, null)) { var result = client.createBatch(req); System.out.println(result.id()); System.out.println(result.status()); } }}Create a new batch processing job
using System;using LiterLlm;
var apiKey = Environment.GetEnvironmentVariable("API_KEY") ?? throw new InvalidOperationException("API_KEY must be set"); using var client = LiterLlmConverter.CreateClient(apiKey, null, null, null, null);var result = await client.CreateBatchAsync(new CreateBatchRequest { CompletionWindow = "24h", Endpoint = "/v1/chat/completions", InputFileId = "file-abc123" });Console.WriteLine(result.Id);Console.WriteLine(result.Status);Create a new batch processing job
require "liter_llm"result = LiterLlm.create_batch(LiterLlm::CreateBatchRequest.new(completion_window: '24h', endpoint: '/v1/chat/completions', input_file_id: 'file-abc123'))puts result.id.inspectputs result.status.inspectCreate a new batch processing job
<?php
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use Liter\Llm\LiterLlm;use Liter\Llm\CreateBatchRequest;$result = LiterLlm::createBatch(new \Liter\Llm\CreateBatchRequest(inputFileId: "file-abc123",endpoint: "/v1/chat/completions",completionWindow: "24h"));var_dump($result->id);var_dump($result->status);Create a new batch processing job
api_key = System.fetch_env!("API_KEY"){:ok, client} = LiterLlm.create_client(api_key)result = LiterLlm.defaultclient_create_batch_async(client, "{\"completion_window\":\"24h\",\"endpoint\":\"/v1/chat/completions\",\"input_file_id\":\"file-abc123\"}")IO.inspect(result.id)IO.inspect(result.status)Create a new batch processing job
import { WasmCreateBatchRequest, createClient } from "@xberg-io/liter-llm-wasm";async function main() { const req: WasmCreateBatchRequest = (() => { const _u0 = WasmCreateBatchRequest.default(); _u0.completionWindow = "24h"; _u0.endpoint = "/v1/chat/completions"; _u0.inputFileId = "file-abc123"; return _u0; })(); const client = createClient("your-api-key"); try { const result = await client.createBatch(req); console.log(result.id); console.log(result.status); } finally { client.free(); }}
void main();Batch Methods
Section titled “Batch Methods”| Method | Description |
|---|---|
create_batch |
Create a batch from an uploaded JSONL file |
retrieve_batch |
Get batch status and results by ID |
list_batches |
List all batches |
cancel_batch |
Cancel a running batch |
Batch Parameters
Section titled “Batch Parameters”| Parameter | Type | Description |
|---|---|---|
input_file_id |
string | ID of the uploaded JSONL file |
endpoint |
string | API endpoint ("/v1/chat/completions", "/v1/embeddings") |
completion_window |
string | Processing window ("24h") |
metadata |
object | Optional key-value metadata |
Responses API
Section titled “Responses API”Create, retrieve, and cancel responses via the Responses API:
Create a basic response using the Responses API
import asyncioimport osfrom liter_llm import create_clientfrom liter_llm._internal_bindings import CreateResponseRequest
async def main() -> None: client = create_client(api_key=os.environ["API_KEY"]) req = CreateResponseRequest.from_json("{\"input\":\"Explain quantum computing in one sentence.\",\"model\":\"gpt-4o\"}") result = await client.create_response(req) print(result.id) print(result.status) print(result.output)
asyncio.run(main())Create a basic response using the Responses API
import { createClient } from "@xberg-io/liter-llm";async function main() { const client = createClient("your-api-key"); const result = await client.createResponse({ input: "Explain quantum computing in one sentence.", model: "gpt-4o" }); console.log(result.id); console.log(result.status); console.log(result.output);}
void main();Create a basic response using the Responses API
use liter_llm::BatchClient;use liter_llm::FileClient;use liter_llm::LlmClient;use liter_llm::ResponseClient;
#[tokio::main]async fn main() { let req_json: serde_json::Value = serde_json::from_str(r#"{"input":"Explain quantum computing in one sentence.","model":"gpt-4o"}"#).unwrap(); let req = serde_json::from_value(req_json).unwrap(); let client = liter_llm::create_client(std::env::var("API_KEY").expect("API_KEY must be set"), None, None, None, None).unwrap(); let result = client.create_response(req).await.expect("call failed"); println!("{:?}", result.id); println!("{:?}", result.status); println!("{:?}", result.output);}Create a basic response using the Responses API
package main
import ( "encoding/json" "fmt" pkg "github.com/xberg-io/liter-llm/packages/go/v2")
func main() { req := pkg.CreateResponseRequest{ Model: `gpt-4o`, Input: json.RawMessage(`"Explain quantum computing in one sentence."`), } client, clientErr := pkg.CreateClient("your-api-key", nil, nil, nil, nil) if clientErr != nil { panic(clientErr) } defer client.Free() result, err := client.CreateResponse(req) if err != nil { panic(err) } fmt.Printf("%+v\n", result.ID) fmt.Printf("%+v\n", result.Status) fmt.Printf("%+v\n", result.Output)}Create a basic response using the Responses API
import io.xberg.literllm.*;
public final class Example { public static void main(String[] args) throws Exception { var reqJson = "{\"input\":\"Explain quantum computing in one sentence.\",\"model\":\"gpt-4o\"}"; var req = JsonUtil.fromJson(reqJson, CreateResponseRequest.class); var apiKey = System.getenv("API_KEY"); if (apiKey == null || apiKey.isEmpty()) throw new IllegalStateException("API_KEY must be set"); try (var client = LiterLlm.createClient(apiKey, null, null, null, null)) { var result = client.createResponse(req); System.out.println(result.id()); System.out.println(result.status()); System.out.println(result.output()); } }}Create a basic response using the Responses API
using System;using System.Text.Json;using LiterLlm;
var ConfigOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };var apiKey = Environment.GetEnvironmentVariable("API_KEY") ?? throw new InvalidOperationException("API_KEY must be set"); using var client = LiterLlmConverter.CreateClient(apiKey, null, null, null, null);var result = await client.CreateResponseAsync(new CreateResponseRequest { Input = JsonSerializer.Deserialize<JsonElement>("\"Explain quantum computing in one sentence.\"", ConfigOptions)!, Model = "gpt-4o" });Console.WriteLine(result.Id);Console.WriteLine(result.Status);Console.WriteLine(result.Output);Create a basic response using the Responses API
require "liter_llm"result = LiterLlm.create_response(LiterLlm::CreateResponseRequest.new(input: 'Explain quantum computing in one sentence.', model: 'gpt-4o'))puts result.id.inspectputs result.status.inspectputs result.output.inspectCreate a basic response using the Responses API
<?php
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use Liter\Llm\LiterLlm;use Liter\Llm\CreateResponseRequest;$req = \Liter\Llm\CreateResponseRequest::from_json(json_encode(["input" => "Explain quantum computing in one sentence.", "model" => "gpt-4o"]));$result = LiterLlm::createResponse($req);var_dump($result->id);var_dump($result->status);var_dump($result->getOutput());Create a basic response using the Responses API
api_key = System.fetch_env!("API_KEY"){:ok, client} = LiterLlm.create_client(api_key)result = LiterLlm.defaultclient_create_response_async(client, "{\"input\":\"Explain quantum computing in one sentence.\",\"model\":\"gpt-4o\"}")IO.inspect(result.id)IO.inspect(result.status)IO.inspect(result.output)Create a basic response using the Responses API
import { WasmCreateResponseRequest, createClient } from "@xberg-io/liter-llm-wasm";async function main() { const req: WasmCreateResponseRequest = (() => { const _u0 = WasmCreateResponseRequest.default(); _u0.input = "Explain quantum computing in one sentence."; _u0.model = "gpt-4o"; return _u0; })(); const client = createClient("your-api-key"); try { const result = await client.createResponse(req); console.log(result.id); console.log(result.status); console.log(result.output); } finally { client.free(); }}
void main();Response Methods
Section titled “Response Methods”| Method | Description |
|---|---|
create_response |
Create a new response |
retrieve_response |
Get a response by ID |
cancel_response |
Cancel a response |
Response Parameters
Section titled “Response Parameters”| Parameter | Type | Description |
|---|---|---|
model |
string | Model to use |
input |
string | Input text or conversation |
instructions |
string | System-level instructions |
max_output_tokens |
int | Maximum tokens to generate |
temperature |
float | Sampling temperature |