Add debug logging to Anthropic OAuth provider
All checks were successful
Build Nanobot OAuth / build (push) Successful in 1m59s

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 <noreply@anthropic.com>
This commit is contained in:
wylab
2026-02-13 15:59:32 +01:00
parent f71b3b3fea
commit 2ab51cb80b

View File

@@ -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,