From 2ab51cb80bb466ca6b982bcf9cd69e3db13365ea Mon Sep 17 00:00:00 2001 From: wylab Date: Fri, 13 Feb 2026 15:59:32 +0100 Subject: [PATCH] Add debug logging to Anthropic OAuth provider Logs thinking block presence, character count, and token usage in API responses. Also logs request parameters including thinking budget configuration. Co-Authored-By: Claude Opus 4.6 --- nanobot/providers/anthropic_oauth.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/nanobot/providers/anthropic_oauth.py b/nanobot/providers/anthropic_oauth.py index c468e62..52dcaa8 100644 --- a/nanobot/providers/anthropic_oauth.py +++ b/nanobot/providers/anthropic_oauth.py @@ -5,10 +5,13 @@ which require Authorization: Bearer header instead of x-api-key. """ import json +import logging from typing import Any import httpx +logger = logging.getLogger(__name__) + from nanobot.providers.base import LLMProvider, LLMResponse, ToolCallRequest from nanobot.providers.oauth_utils import get_auth_headers, get_claude_code_system_prefix @@ -223,6 +226,12 @@ class AnthropicOAuthProvider(LLMProvider): if tools: payload["tools"] = tools + logger.info( + "Anthropic request: model=%s max_tokens=%d thinking=%s", + payload.get("model"), payload.get("max_tokens"), + payload.get("thinking", "disabled"), + ) + response = await client.post( self._get_api_url(), headers=self._get_headers(), @@ -304,6 +313,21 @@ class AnthropicOAuthProvider(LLMProvider): ), } + # Log usage and thinking info + if thinking_blocks: + thinking_chars = sum(len(b.get("thinking", "")) for b in thinking_blocks) + logger.info( + "Anthropic response: %d thinking block(s) (%d chars), " + "input=%d output=%d tokens", + len(thinking_blocks), thinking_chars, + usage.get("prompt_tokens", 0), usage.get("completion_tokens", 0), + ) + else: + logger.info( + "Anthropic response: no thinking blocks, input=%d output=%d tokens", + usage.get("prompt_tokens", 0), usage.get("completion_tokens", 0), + ) + return LLMResponse( content=text_content or None, tool_calls=tool_calls,