mem0ai/mem0 · error · Error
Together API key is required
Error message
Together API key is required
What it means
TogetherEmbedder (which extends OpenAIEmbedder) requires an API key at construction time. It checks config.apiKey first, then the TOGETHER_API_KEY environment variable; if neither is set it throws immediately, before any network call. This is a fail-fast configuration error, not a runtime API error.
Source
Thrown at mem0-ts/src/oss/src/embeddings/together.ts:14
import { OpenAIEmbedder } from "./openai";
import { EmbeddingConfig } from "../types";
const DEFAULT_BASE_URL = "https://api.together.ai/v1";
const DEFAULT_MODEL = "intfloat/multilingual-e5-large-instruct";
export class TogetherEmbedder extends OpenAIEmbedder {
constructor(config: EmbeddingConfig) {
const openAICompatibleConfig = { ...config };
delete openAICompatibleConfig.embeddingDims;
const apiKey = config.apiKey || process.env.TOGETHER_API_KEY;
if (!apiKey) {
throw new Error("Together API key is required");
}
super({
...openAICompatibleConfig,
apiKey,
// Honor TOGETHER_API_BASE like the Together LLM does, so a user behind a
// gateway who sets it gets it for embeddings too instead of silently
// hitting api.together.ai.
baseURL:
config.baseURL ||
config.url ||
process.env.TOGETHER_API_BASE ||
DEFAULT_BASE_URL,
model: config.model || DEFAULT_MODEL,
});
}
}
View on GitHub (pinned to 001c235229)
Solutions
- Set TOGETHER_API_KEY in the environment or pass apiKey in the embedder config
- If using dotenv, ensure import 'dotenv/config' (or config()) runs before the Memory/TogetherEmbedder is constructed
- Check the exact spelling TOGETHER_API_KEY and that it is exported in the deploy environment
- Get a valid key from api.together.ai if you do not have one
Example fix
// before
const memory = new Memory({ embedder: { provider: "together" } }); // no key anywhere
// after
const memory = new Memory({
embedder: { provider: "together", config: { apiKey: process.env.TOGETHER_API_KEY! } },
}); Defensive patterns
Strategy: validation
Validate before calling
const apiKey = config.apiKey ?? process.env.TOGETHER_API_KEY;
if (!apiKey) throw new Error("TOGETHER_API_KEY missing - set it before constructing Memory"); Type guard
function isMissingApiKeyError(err: unknown): boolean {
return err instanceof Error && err.message === "Together API key is required";
} Try / catch
try {
new TogetherEmbedder(config);
} catch (err) {
if (err instanceof Error && err.message === "Together API key is required") {
throw new Error("Configuration error: provide config.apiKey or set TOGETHER_API_KEY");
}
throw err;
} Prevention
- Fail fast on config: assert required env vars at process start, not on first embed
- Load dotenv at the entry point before any SDK construction
- Add a startup config schema check (e.g. zod) covering apiKey fields
When it happens
Trigger: Constructing Memory or TogetherEmbedder with provider 'together' while passing no apiKey and having no TOGETHER_API_KEY in the environment; env var name typo (TOGETHER_APIKEY, TOGETHER_KEY); .env file loaded after module initialization or not loaded at all.
Common situations: CI environment missing the secret; dotenv imported after Memory construction; key set in one shell but the process runs elsewhere (Docker, serverless); confusing the Together key with the OpenAI key.
Related errors
- Anthropic API key is required
- Together API key is required
- Together LLM failed: ${message}
- xAI API key is required
- Pinecone API key required: pass apiKey or set PINECONE_API_K
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/0925718071b66546.
Report an issue: GitHub.