mem0ai/mem0 · error

Together LLM failed: ${message}

Error message

Together LLM failed: ${message}

What it means

Thrown by the Together AI LLM wrapper in the OSS TypeScript SDK when the underlying OpenAI-compatible call to Together's API fails while generating a structured response (generateResponse). The wrapper catches any error from the parent OpenAILLM implementation and re-throws it prefixed with 'Together LLM failed' plus the original message. The root cause is almost always an HTTP, auth, model, or network problem reported by the Together API.

Source

Thrown at mem0-ts/src/oss/src/llms/together.ts:31

      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 {
      return await super.generateResponse(messages, responseFormat, tools);
    } catch (err) {
      const message = err instanceof Error ? err.message : String(err);
      throw new Error(`Together LLM failed: ${message}`);
    }
  }

  async generateChat(messages: Message[]): Promise<LLMResponse> {
    try {
      return await super.generateChat(messages);
    } catch (err) {
      const message = err instanceof Error ? err.message : String(err);
      throw new Error(`Together LLM failed: ${message}`);
    }
  }
}

View on GitHub (pinned to 001c235229)

Solutions

  1. Check the original message appended after 'Together LLM failed:' — it carries Together's HTTP status/body (401 = bad key, 404 = bad model, 429 = rate limit).
  2. Verify the API key: set config.llm.config.apiKey explicitly or export TOGETHER_API_KEY in the process environment.
  3. Verify the model id is a current Together model (e.g. 'meta-llama/Llama-3.3-70B-Instruct-Turbo'); fix config.llm.config.model.
  4. If rate-limited, add backoff/retry around the Memory call or reduce concurrency.
  5. If using a custom baseURL, confirm it is reachable from the runtime (curl it from the same host/container).

Example fix

// before
const memory = new Memory({
  llm: { provider: 'together', config: { model: 'llama-3.3-70b' } }, // wrong id, 404 at call time
});
await memory.add('hello', { userId: 'u1' }); // throws Together LLM failed: 404 ...

// after
const memory = new Memory({
  llm: {
    provider: 'together',
    config: {
      apiKey: process.env.TOGETHER_API_KEY,
      model: 'meta-llama/Llama-3.3-70B-Instruct-Turbo',
    },
  },
});
Defensive patterns

Strategy: retry

Validate before calling

import Together from 'together-ai';
async function assertTogetherReachable(apiKey: string, model: string) {
  const client = new Together({ apiKey });
  await client.models.retrieve(model); // 404 here means bad model id, before Memory runs
}

Type guard

function isTransientLlmError(err: unknown): boolean {
  const msg = err instanceof Error ? err.message : String(err);
  return /Together LLM failed:.*(429|500|502|503|504|ECONNRESET|ETIMEDOUT|fetch failed)/.test(msg);
}

Try / catch

try {
  await memory.add(text, { filters: { userId } });
} catch (err) {
  const msg = err instanceof Error ? err.message : String(err);
  if (/Together LLM failed:/.test(msg) && /401|invalid api key/i.test(msg)) {
    // config problem: surface to operator, do not retry
    throw new Error('Together credentials invalid — check TOGETHER_API_KEY');
  }
  if (/429|5\d\d|ETIMEDOUT|fetch failed/.test(msg)) {
    await backoffRetry(() => memory.add(text, { filters: { userId } }));
  } else throw err;
}

Prevention

When it happens

Trigger: Calling memory.add(), memory.search(), or any Memory pipeline step that invokes the LLM while config.llm.provider is 'together', and the POST to https://api.together.xyz/v1/chat/completions fails: invalid/expired TOGETHER_API_KEY, unknown model name in config.llm.config.model, malformed responseFormat, rate limiting, or a network/DNS failure.

Common situations: Setting an incorrect model id (e.g. a typo or a deprecated Together model), missing TOGETHER_API_KEY in the environment where the Node process runs, exceeding Together rate limits under load, or routing through a custom baseURL that is unreachable. Also triggered when Together returns a non-OpenAI-shaped error payload that the parent class surfaces as a generic Error.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/1d9db73fadd48efc. Report an issue: GitHub.