mem0ai/mem0 · error
Together API key is required
Error message
Together API key is required
What it means
Thrown synchronously by the TogetherLLM constructor when no Together AI API key is resolved. The provider checks config.apiKey, then the TOGETHER_API_KEY environment variable, and throws when both are missing — the fail-fast guard before building the OpenAI-compatible client for api.together.ai.
Source
Thrown at mem0-ts/src/oss/src/llms/together.ts:9
import { OpenAILLM } from "./openai";
import { LLMConfig, Message } from "../types";
import { LLMResponse } from "./base";
export class TogetherLLM extends OpenAILLM {
constructor(config: LLMConfig) {
const apiKey = config.apiKey || process.env.TOGETHER_API_KEY;
if (!apiKey) {
throw new Error("Together API key is required");
}
super({
...config,
apiKey,
baseURL:
config.baseURL ||
process.env.TOGETHER_API_BASE ||
"https://api.together.ai/v1",
model: config.model || "MiniMaxAI/MiniMax-M3",
});
}
async generateResponse(
messages: Message[],
responseFormat?: { type: string },
tools?: any[],
): Promise<string | LLMResponse> {
try {View on GitHub (pinned to 001c235229)
Solutions
- Export TOGETHER_API_KEY with a key from the Together settings page.
- Or pass it explicitly: llm: { provider: 'together', config: { apiKey: process.env.TOGETHER_API_KEY } }.
- Load dotenv before constructing Memory.
- Add TOGETHER_API_KEY to deployment/CI secrets.
Example fix
// before
const mem = new Memory({ llm: { provider: 'together', config: {} } });
// throws: Together API key is required
// after
import 'dotenv/config';
const mem = new Memory({
llm: { provider: 'together', config: { apiKey: process.env.TOGETHER_API_KEY! } },
}); Defensive patterns
Strategy: validation
Validate before calling
function assertTogetherKey(cfg: LLMConfig) {
if (!cfg.apiKey && !process.env.TOGETHER_API_KEY) {
throw new Error('TOGETHER_API_KEY not set — create one at api.together.ai/settings/api-keys');
}
} Type guard
const hasTogetherKey = (cfg: LLMConfig): boolean => Boolean(cfg.apiKey || process.env.TOGETHER_API_KEY);
Try / catch
try { new TogetherLLM(config); } catch (e) {
if ((e as Error).message === 'Together API key is required') throw new StartupConfigError('TOGETHER_API_KEY missing');
throw e;
} Prevention
- Export TOGETHER_API_KEY (exact name) or pass apiKey in config.
- Load dotenv before constructing Memory.
- Validate provider-specific env vars in a boot schema check.
When it happens
Trigger: Instantiating TogetherLLM (provider 'together') with apiKey absent/empty and TOGETHER_API_KEY unset at construction time.
Common situations: Key not created at api.together.ai/settings/api-keys; env var set only in local shell but missing in CI/production; dotenv loaded after Memory construction; key name typo (TOGETHERAI_API_KEY).
Related errors
- DeepSeek API key is required
- Groq API key is required
- MiniMax API key is required
- Sarvam API key is required
- Mistral API key is required
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/b365bfad5b08fc28.
Report an issue: GitHub.