Together AI
Use Together AI's OpenAI-compatible open-model inference with Anvia.
Together AI exposes an OpenAI-compatible surface at https://api.together.ai/v1 covering chat completions, vision, function calling, structured outputs, embeddings, image generation, text-to-speech, and speech-to-text. In Anvia, configure OpenAIClient with that baseUrl, then pass Together model ids to completionModel(...).
Create the Client
import { AgentBuilder } from "@anvia/core";
import { OpenAIClient } from "@anvia/openai";
const client = new OpenAIClient({
baseUrl: "https://api.together.ai/v1",
apiKey: process.env.TOGETHER_API_KEY,
});
const model = client.completionModel("openai/gpt-oss-20b");
const agent = new AgentBuilder("support", model)
.instructions("Answer support questions clearly.")
.build();
const response = await agent.prompt("Hello!").send();
console.log(response.output);baseUrl makes Anvia use the OpenAI-compatible chat completion adapter. Together model ids are namespaced as <provider>/<model_name> and are not interchangeable with OpenAI model strings.
Get the Model List
Together exposes a /v1/models endpoint. Because the client was created with baseUrl, listModels() calls Together's /models endpoint.
const models = await client.listModels();
console.table(
models.data.map((model) => ({
id: model.id,
name: model.name,
contextLength: model.contextLength,
})),
);Use the id field directly with completionModel(...).
Endpoint Coverage
| Capability | OpenAI SDK call | Together status |
|---|---|---|
| Chat completions (with streaming) | chat.completions.create | Supported |
| Vision (image inputs) | chat.completions.create with image content | Supported |
| Function calling | chat.completions.create with tools and tool_choice | Supported |
| Structured outputs | chat.completions.create with response_format | Supported |
| Embeddings | embeddings.create | Supported |
| Image generation | images.generate | Supported |
| Text-to-speech | audio.speech.create | Supported |
| Speech-to-text and translation | audio.transcriptions.create, audio.translations.create | Supported |
| Responses API | responses.create | Not supported — use chat.completions.create |
| Assistants, Threads, Runs | assistants.*, threads.*, runs.* | Not supported — build agent loops with function calling |
| OpenAI-shaped Batch and Files | batches.*, files.* | Not supported — use Together's native Batch and Files APIs |
| Moderations | moderations.create | Not supported — use Llama Guard via chat completions |
Notes
- Together API keys are passed as bearer tokens in the
Authorizationheader. - Model identifiers are namespaced. Use Together ids like
openai/gpt-oss-20bormeta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8. OpenAI ids such asgpt-4oortext-embedding-3-largereturn404. - Parameter quirks:
seedis best-effort and not guaranteed deterministic.nis supported on most chat models but not all.logit_biasis unsupported on most models.service_tier,store,metadata, andpredictionare accepted but ignored.reasoning_effortworks on GPT-OSS models (low,medium,high). - Response shape:
usageincludesprompt_tokens,completion_tokens, andtotal_tokens. Some models add Together-only fields likecached_tokensandreasoning_tokens. Reasoning models return traces in a top-levelreasoningfield on the assistant message rather than OpenAI's nested object. - Errors follow the OpenAI shape
{ "error": { "message", "type", "code" } }, buttypeandcodevalues are Together's. Match on HTTP status (400, 401, 404, 429, 500, 503) for portable handling. - Together-native endpoints not exposed through the OpenAI SDK include video generation, image edits, reasoning controls beyond
reasoning_effort, and Together's richer logprobs surface.
For current Together API details, see the Together OpenAI compatibility docs and the Together model catalog.
