nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Feature] Generic extraBody for every OpenAI-compatible provider (chat_template_kwargs, num_ctx, keep_alive)

Open akramcodez opened this issue 3 weeks ago • 2 comments

Description

There is no way to send extra request-body fields to an OpenAI-compatible provider. buildProviderOptions in source/ai-sdk-client/chat/provider-options.ts forwards extraBody only for OpenRouter (openrouter.extraBody, typed in source/types/config.ts). For every other provider, including Ollama, llama.cpp, vLLM, LM Studio and DeepSeek-style endpoints, there is no equivalent.

Many of the knobs that matter most for local inference are only reachable through the request body:

  • chat_template_kwargs (for example enable_thinking: false on Qwen3 style templates in vLLM and llama.cpp)
  • options.num_ctx, keep_alive and options.num_predict for Ollama's native fields
  • top_k, min_p, repeat_penalty, mirostat and other sampler fields that are not part of the standard OpenAI schema
  • reasoning_effort and vendor-specific reasoning switches (see also #1361 for the narrower reasoning-effort request)

Use Case

A user runs Qwen3 through vLLM and wants thinking disabled for fast edits, or runs Ollama and wants a larger num_ctx and a long keep_alive so the model is not reloaded between turns. Today the only options are a proxy that rewrites the request or editing the Modelfile or server flags for every use case. Searches for extraBody, chat_template_kwargs, enable_thinking and keep_alive upstream return nothing.

Proposed Solution

Add a generic extraBody object to every provider entry in agents.config.json. The object is merged into the JSON body of each chat completion request for any provider that uses the OpenAI-compatible path. Per-model overrides would be a natural extension:

{
  "name": "vllm",
  "baseUrl": "http://localhost:8000/v1",
  "models": ["qwen3-coder"],
  "extraBody": {"chat_template_kwargs": {"enable_thinking": false}, "top_k": 20}
}

Alternatives Considered

  • Put a rewriting proxy in front of the server. It works but adds a moving part to a tool that is meant to be simple to run locally.
  • Add one dedicated config field per vendor option. This does not scale and always lags behind servers.

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] This feature aligns with the project's goals (local-first AI assistance)

Implementation Notes (optional)

The OpenRouter branch in buildProviderOptions already shows the shape: keys are placed under the provider id used by the OpenAI-compatible SDK provider and are spread into the request body. The same mechanism can serve all openai-compatible providers. Values should go through the existing $VAR substitution so secrets can stay in the environment, and keys that the client sets itself (model, messages, tools, stream) should win to avoid breaking tool calling.

akramcodez avatar Nov 12 '26 14:11 akramcodez

I'd like to take this issue. I'll add generic extraBody forwarding for OpenAI-compatible chat requests, preserve config environment substitution and client-owned request fields, and cover the behavior with focused provider-options tests.

ducanhnguyen223 avatar Nov 13 '26 01:11 ducanhnguyen223

Hi @ducanhnguyen223, thanks for your interest in the issue! Before opening a PR, please comment on the issue first and wait to be assigned. This helps us avoid duplicate work PRs opened without an assignment may be closed. Thanks!

addyCooks avatar Nov 14 '26 07:11 addyCooks