agentmemory icon indicating copy to clipboard operation
agentmemory copied to clipboard

OpenAI-compatible provider cannot send endpoint-specific request fields (OpenRouter provider routing)

Open Rex57 opened this issue 1 month ago • 0 comments

Current-main boundary

On main 007a1a7 (0.9.30), OpenAIProvider sends a fixed body: model, max_tokens, stream, messages, and reasoning_effort when set. Several OpenAI-compatible endpoints need one more field for correct cost or behavior, and there is no way to add it.

The user problem

I route the LLM through OpenRouter with OPENAI_BASE_URL=https://openrouter.ai/api/v1, because this client can turn reasoning off (OPENAI_REASONING_EFFORT=none) and the native OpenRouter client cannot. To keep cost down I use the :floor variant, which picks the cheapest provider per request. The model's prompt cache is per provider, so a provider change between calls loses the cache. OpenRouter solves this with the provider request object (order, allow_fallbacks, only, sort), but agentmemory cannot send it. The same gap exists for other compatible servers (for example vLLM chat_template_kwargs, or top_k).

Required behavior

  • An optional OPENAI_EXTRA_BODY setting holds a JSON object whose fields are added to every chat request of the OpenAI-compatible provider.
  • The fields agentmemory sets itself (model, messages, max_tokens, stream, reasoning_effort) win over the same keys in the extra body.
  • A value that is not a JSON object fails at startup with an error that names the setting, like the existing dimension settings do.
  • Unset: the request body is byte-for-byte what it is today.

Acceptance checks

Provider tests: unset → unchanged body; {"provider":{"order":["deepinfra"],"allow_fallbacks":false}} → field present; {"model":"x"} → configured model still sent; invalid JSON and a JSON array → constructor throws.

Source and existing work

OpenAIProvider request body.

Related: #808 and PR #810 (reasoning options on the native OpenRouter client), #1328 (custom request headers).

Environment: agentmemory 0.9.30, Node v26.10.0, macOS 27.0.1 (arm64).

Rex57 avatar Oct 08 '26 06:10 Rex57