Roo-Code/src/api/providers
Hannes Rudolph d1baa6e849
fix: add cache reporting support for OpenAI-Native provider (#7602)
* fix: add cache reporting support for OpenAI-Native provider

- Add normalizeUsage method to properly extract cache tokens from Responses API
- Support both detailed token shapes (input_tokens_details) and legacy fields
- Calculate cache read/write tokens with proper fallbacks
- Include reasoning tokens when available in output_tokens_details
- Ensure accurate cost calculation using uncached input tokens

This fixes the issue where caching information was not being reported
when using the OpenAI-Native provider with the Responses API.

* fix: improve cache token normalization and add comprehensive tests

- Add fallback to derive total input tokens from details when totals are missing
- Remove unused convertToOpenAiMessages import
- Add comment explaining cost calculation alignment with Gemini provider
- Add comprehensive test coverage for normalizeUsage method covering:
  - Detailed token shapes with cached/miss tokens
  - Legacy field names and SSE-only events
  - Edge cases including missing totals with details-only
  - Cost calculation with uncached input tokens

* fix: address PR review comments

- Remove incorrect fallback to missFromDetails for cache write tokens
- Fix cost calculation to pass total input tokens (calculateApiCostOpenAI handles subtraction)
- Improve readability by extracting cache detail checks to intermediate variables
- Remove redundant ?? undefined
- Update tests to reflect correct behavior (miss tokens are not cache writes)
- Add clarifying comments about cache miss vs cache write tokens
2025-09-02 19:59:16 -04:00
..
__tests__ fix: add cache reporting support for OpenAI-Native provider (#7602) 2025-09-02 19:59:16 -04:00
fetchers Move @roo-code/cloud to the Roo-Code repo (#7503) 2025-08-28 11:18:45 -07:00
utils feat: add configurable API request timeout for local providers (#6531) 2025-08-12 11:48:45 -04:00
anthropic-vertex.ts Move provider data into @roo-code/types (#4153) 2025-05-30 14:54:48 -07:00
anthropic.ts feat: Update Claude Sonnet 4 context window to 1 million tokens (#7005) 2025-08-12 14:40:42 -04:00
base-openai-compatible-provider.ts Pass task ID in the Roo provider request headers (#7303) 2025-08-21 20:27:21 -07:00
base-provider.ts Move provider data into @roo-code/types (#4153) 2025-05-30 14:54:48 -07:00
bedrock.ts Fix: AWS Bedrock 1M context - Move anthropic_beta to additionalModelRequestFields (#7056) 2025-08-13 15:26:50 -04:00
cerebras.ts Add Qwen 3 Coder from Cerebras (#6562) 2025-08-01 15:29:33 -04:00
chutes.ts feat: Add DeepSeek R1 support to Chutes provider (#4523) (#4525) 2025-06-12 11:39:41 -04:00
claude-code.ts Feature/vertex ai model name conversion (#5728) 2025-07-15 14:15:33 -04:00
constants.ts feat: add User-Agent header to API providers (#5492) 2025-07-08 23:19:56 -04:00
deepseek.ts Move provider data into @roo-code/types (#4153) 2025-05-30 14:54:48 -07:00
doubao.ts Support new LLM provider: Doubao (#6345) 2025-07-30 16:54:16 -04:00
fake-ai.ts Add a new @roo-code/types package and use it everywhere (#3912) 2025-05-26 12:06:45 -07:00
featherless.ts feat: Featherless provider (#7235) 2025-08-20 10:42:57 -07:00
fireworks.ts Add the fireworks AI provider (#6652) 2025-08-04 19:27:12 -07:00
gemini.ts Feat: Adding Gemini tools - URL Context and Grounding with Google Search (#5959) 2025-07-27 14:34:55 -04:00
glama.ts Move provider data into @roo-code/types (#4153) 2025-05-30 14:54:48 -07:00
groq.ts feat: add prompt caching support for Kimi K2 on Groq (#7324) 2025-08-22 09:40:21 -07:00
huggingface.ts Hugging Face provider: add more details (#6190) 2025-07-25 20:09:09 -04:00
human-relay.ts Add a new @roo-code/types package and use it everywhere (#3912) 2025-05-26 12:06:45 -07:00
index.ts feat: Add Vercel AI Gateway provider integration (#7396) 2025-08-26 13:41:02 -07:00
io-intelligence.ts Add IO Intelligence Provider (#6875) 2025-08-11 16:54:35 -04:00
lite-llm.ts feat: add prompt caching support for LiteLLM (#5791) (#6074) 2025-07-28 12:56:06 -07:00
lm-studio.ts feat: add configurable API request timeout for local providers (#6531) 2025-08-12 11:48:45 -04:00
mistral.ts fix: handle Mistral thinking content as reasoning chunks (#7106) 2025-08-23 06:33:43 -07:00
moonshot.ts feat: add moonshot provider (#6046) 2025-07-22 00:37:24 -04:00
native-ollama.ts feat: add Ollama API key support for Turbo mode (#7425) 2025-08-30 19:20:31 -04:00
ollama.ts feat: add Ollama API key support for Turbo mode (#7425) 2025-08-30 19:20:31 -04:00
openai-native.ts fix: add cache reporting support for OpenAI-Native provider (#7602) 2025-09-02 19:59:16 -04:00
openai.ts fix: omit temperature parameter when not explicitly set for OpenAI Compatible providers (#7188) 2025-08-21 02:14:03 -07:00
openrouter.ts feat: add optional input image parameter to image generation tool (#7525) 2025-08-29 11:08:21 -04:00
qwen-code.ts Fix build error (#7397) 2025-08-25 12:18:59 -07:00
requesty.ts feat: add custom base URL support for Requesty provider (#7337) 2025-08-22 13:43:08 -07:00
roo.ts Move @roo-code/cloud to the Roo-Code repo (#7503) 2025-08-28 11:18:45 -07:00
router-provider.ts feat: adding default headers and testing for litellm fetcher (#5242) 2025-06-30 20:23:11 -04:00
sambanova.ts feat: add SambaNova provider integration (#6188) 2025-07-30 12:47:12 -04:00
unbound.ts Add cache breakpoints for custom vertex models on Unbound (#4585) 2025-06-13 08:29:40 -04:00
vercel-ai-gateway.ts feat: Add Vercel AI Gateway provider integration (#7396) 2025-08-26 13:41:02 -07:00
vertex.ts Add gemini pro 06 05 (#4386) 2025-06-05 17:49:12 -04:00
vscode-lm.ts feat: enhance token counting by extracting text from messages using VSCode LM API (#6424) 2025-07-30 16:56:01 -04:00
xai.ts update xai models and pricing (#4315) 2025-06-12 11:59:45 -04:00
zai.ts Add Z AI provider (#6657) 2025-08-04 10:06:46 -04:00