Together AI

Run batches on Together AI's Batch API — a leaner line shape and a presigned-URL upload.

Together AI's Batch API mirrors OpenAI's (Files API + /batches) with two twists: a leaner { custom_id, body } line shape with the endpoint declared on the batch, and a presigned-URL file upload in place of OpenAI's direct multipart POST. Batchwork handles both.

PropertyValue
ShapeJSONL file upload (body-only)
Endpoint/v1/chat/completions
ResultsOutput + error files (JSONL)
WebhooksPoll-only (managed by the server)
Env varTOGETHER_API_KEY
Package@ai-sdk/togetherai
Base URLhttps://api.together.xyz/v1

Example

import { batch } from "batchwork";
import { togetherai } from "@ai-sdk/togetherai";

const job = await batch({
  model: togetherai("meta-llama/Llama-3.3-70B-Instruct-Turbo"),
  requests: [
    { customId: "fr", prompt: "Capital of France? One word." },
    { customId: "jp", prompt: "Capital of Japan? One word." },
  ],
});

The "together/…" and "togetherai/…" string forms both resolve here — see Models.

How it works

  1. Build — each request becomes a leaner { custom_id, body } line; the endpoint is declared on the batch rather than per line.
  2. Upload — Together uses a presigned URL: POST /files with metadata only returns a 302 with a signed Location and file id, the raw bytes are PUT to that URL, then POST /files/{id}/preprocess finalizes it (purpose=batch-api).
  3. Create — the batch references the uploaded file id.
  4. Poll & read — Batchwork polls status, then downloads the OpenAI-shaped output/error files.

Presigned upload Location values must be HTTPS and cannot target localhost or private-network URL literals.

Notes

Together has no native batch webhook, so it is poll-only. Use the server layer for unified completion events.

Credentials

Set TOGETHER_API_KEY, or pass apiKey / baseURL / headers to batch(). Install the peer dependency:

bun add @ai-sdk/togetherai

On this page