chroma-core/chroma · error · Error
Error calling Together AI API: ${error.message}
Error message
Error calling Together AI API: ${error.message} What it means
Catch-all wrapper thrown by TogetherAIEmbeddingFunction.generate() for any Error raised while calling Together AI: fetch network failures, response.json() throwing a SyntaxError on non-JSON bodies (e.g. HTML 502 pages), TypeError when `resp.data` is present but not an array (.map is not a function), or the inner 'Invalid response format' throw whose message gets doubled up. The original cause is preserved as the message suffix, so read everything after 'Error calling Together AI API:'.
Source
Thrown at clients/js/packages/chromadb-core/src/embeddings/TogetherAIEmbeddingFunction.ts:69
const response = await fetch(ENDPOINT, {
method: "POST",
headers: this.headers,
body: JSON.stringify(payload),
});
const resp = await response.json();
if (!resp.data) {
throw new Error("Invalid response format from Together AI API");
}
const embeddings = resp.data.map(
(item: { embedding: number[] }) => item.embedding,
);
return embeddings;
} catch (error) {
if (error instanceof Error) {
throw new Error(`Error calling Together AI API: ${error.message}`);
} else {
throw new Error(`Error calling Together AI API: ${error}`);
}
}
}
buildFromConfig(config: StoredConfig): IEmbeddingFunction {
return new TogetherAIEmbeddingFunction({
model_name: config.model_name,
api_key_env_var: config.api_key_env_var,
});
}
getConfig(): StoredConfig {
return {
model_name: this.model_name,
api_key_env_var: this.api_key_env_var,
};View on GitHub (pinned to aecdd12c8a)
Solutions
- Read the suffix after 'Error calling Together AI API:' — SyntaxError means non-JSON body, TypeError means malformed JSON shape, fetch errors mean network.
- For network/5xx causes, retry with backoff (the request is idempotent).
- Verify connectivity: curl -i https://api.together.xyz/v1/embeddings from the same host/container.
- Check status.together.ai for ongoing incidents.
Example fix
// before
const embeddings = await togetherFn.generate(texts); // single shot, any blip fails the job
// after
const embeddings = await withRetry(() => togetherFn.generate(texts), {
retries: 3,
baseDelayMs: 500,
isRetryable: (e) => /SyntaxError|fetch failed|ECONN|ETIMEDOUT/i.test(e.message),
}); Defensive patterns
Strategy: retry
Try / catch
const RETRYABLE = /fetch failed|ECONN|ETIMEDOUT|ENOTFOUND|SyntaxError|Unexpected token|5[0-9][0-9]/i;
const generateWithRetry = async (texts: string[], attempts = 3) => {
for (let i = 0; i < attempts; i++) {
try {
return await fn.generate(texts);
} catch (e) {
const msg = e instanceof Error ? e.message : String(e);
if (i === attempts - 1 || !RETRYABLE.test(msg)) throw e;
await new Promise((r) => setTimeout(r, 2 ** i * 500));
}
}
throw new Error("unreachable");
}; Prevention
- Treat fetch/json-parse failures from Together as transient and retry with exponential backoff.
- Keep ingestion jobs restartable (idempotent ids) so a network blip never corrupts a batch.
- Monitor Together status and gate large embedding jobs on a health probe.
When it happens
Trigger: fetch() rejects (DNS failure, offline, TLS/proxy cert error, timeout); Together/gateway returns HTML or empty body so response.json() throws SyntaxError "Unexpected token < in JSON"; response `data` field is a non-array (error payloads like {data: "unauthorized"}).
Common situations: Ephemeral network drops in CI pipelines; corporate proxies returning HTML error pages on 502/503; Together API incidents; Node without internet access in a locked-down container.
Related errors
- Error calling Jina AI API: ${error.message}
- Error calling Cloudflare Workers AI API: ${error.message}
- Failed to generate embeddings: ${response.statusText}
- Together AI API key is required. Please provide it in the co
- Invalid response format from Together AI API
AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16).
Data as JSON: /api/errors/fc2fd6fa0e09ab8b.
Report an issue: GitHub.