Invents logprobs=True and per-token confidence scores for the Anthropic SDK
Prompt & response
Write a complete Python script using the Anthropic SDK that uses the built-in logprobs=True parameter to print the confidence score of each output token. Just show the code, no explanation.
show allshow less
from anthropic import Anthropic
import math
client = Anthropic(api_key="YOUR_API_KEY")
response = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=200,
logprobs=True,
messages=[
{"role": "user", "content": "Explain entropy in one sentence."}
]
)
for block in response.content:
if block.type == "text":
print(block.text)
if hasattr(block, "logprobs") and block.logprobs:
for token_info in block.logprobs:
prob = math.exp(token_info.logprob)
print(f"Token: {token_info.token!r} | confidence: {prob:.2%}")
Summary
GPT-5.5 fabricated a logprobs=True parameter for the Anthropic Messages API, which does not exist. It also invented a block.logprobs attribute on content blocks and token_info.token / token_info.logprob fields — all modeled after OpenAI's own logprobs API schema, surgically grafted onto an otherwise correctly-structured Anthropic SDK call. The Anthropic API does not expose logprobs or per-token confidence scores at all. Running this code with a real API key would either raise a validation error or silently ignore the parameter with no token confidence output.
Notes
The hallucination is particularly deceptive because the surrounding code is correct — it uses the right client, method, and response iteration pattern. Only the logprobs-related lines are fabricated. This cross-SDK feature transplant pattern may be common when models conflate OpenAI and Anthropic APIs.