Describe the bug
When using AnthropicChatModel with a proxy service (anthropic proxy api) that forwards Anthropic API responses, the SDK throws AnthropicInvalidDataException: id is not set.
This issue occurs because some proxy services strip the id field from the response body for privacy reasons.
To Reproduce
Steps
- Configure
AnthropicChatModel with a proxy URL:
AnthropicChatModel model = AnthropicChatModel.builder()
.apiKey("sk-ant-...") // Your API key
.modelName("claude-sonnet-4-5-20250929")
.baseUrl("Anthropic Proxy URL") // Proxy URL
.stream(false)
.build();
ReActAgent agent = ReActAgent.builder()
.name("TestAgent")
.sysPrompt("You are a math assistant.")
.model(model)
.build();
Msg response = agent.call(Msg.builder()
.textContent("2+3等于多少?")
.build()).block();
-
Execute the code
-
See error: AnthropicInvalidDataException: id is not set
Curl Command (Alternative Reproduction)
curl -X POST "https://anthropicProxyApi/v1/messages" \
-H "Content-Type: application/json" \
-H "x-api-key: sk-ant-YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-dangerous-direct-browser-access: true" \
-d '{
"model": "claude-sonnet-4-5-20250929",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "2+3等于多少?"
}
]
}'
Expected behavior
The SDK should handle responses that are missing the id field gracefully. The id field is important for tracking but not critical for response parsing.
Error messages
com.anthropic.errors.AnthropicInvalidDataException: `id` is not set
at com.anthropic.core.JsonField.getRequired$anthropic_java_core(Values.kt:174)
at com.anthropic.models.messages.Message.id(Message.kt:68)
at io.agentscope.core.formatter.anthropic.AnthropicResponseParser.parseMessage(AnthropicResponseParser.java:97)
at io.agentscope.core.formatter.anthropic.AnthropicChatFormatter.parseResponse(AnthropicChatFormatter.java:47)
at io.agentscope.core.model.AnthropicChatModel.lambda$doStream$1(AnthropicChatModel.java:194)
Response from Proxy (missing id field)
{
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "2 + 3 = 5"
}
],
"model": "claude-sonnet-4-5-20250929",
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 57,
"output_tokens": 8
}
}
Environment
- AgentScope-Java Version: 1.0.7
- Java Version: 17+
- OS: macOS
Additional context
Root Cause
The Anthropic SDK 2.11.0 requires the id field in the message response and validates it with @Required annotation during deserialization.
Affected Components
AnthropicChatModel (io.agentscope.core.model.AnthropicChatModel)
AnthropicResponseParser (io.agentscope.core.formatter.anthropic.AnthropicResponseParser)
Behavior Comparison
| Scenario |
Current Behavior |
Expected Behavior |
Proxy without id field |
❌ Throws exception |
✅ Should handle gracefully |
| Official Anthropic API |
❓ Not tested yet |
✅ Should work |
Suggested Fixes
-
Fix in Anthropic SDK (Recommended): Make the id field optional in the SDK's Message class instead of required.
-
Fix in AgentScope Response Parser: Modify AnthropicResponseParser.parseMessage() to use a custom ObjectMapper that can deserialize responses without the id field.
-
Proxy-Friendly Configuration: Add a configuration option to AnthropicChatModel.Builder to generate fallback IDs for responses missing the id field.
Note
This issue is specific to proxy services that modify Anthropic API responses. The official Anthropic API always includes the id field.
Describe the bug
When using
AnthropicChatModelwith a proxy service (anthropic proxy api) that forwards Anthropic API responses, the SDK throwsAnthropicInvalidDataException: id is not set.This issue occurs because some proxy services strip the
idfield from the response body for privacy reasons.To Reproduce
Steps
AnthropicChatModelwith a proxy URL:Execute the code
See error:
AnthropicInvalidDataException: id is not setCurl Command (Alternative Reproduction)
Expected behavior
The SDK should handle responses that are missing the
idfield gracefully. Theidfield is important for tracking but not critical for response parsing.Error messages
Response from Proxy (missing
idfield){ "type": "message", "role": "assistant", "content": [ { "type": "text", "text": "2 + 3 = 5" } ], "model": "claude-sonnet-4-5-20250929", "stop_reason": "end_turn", "stop_sequence": null, "usage": { "input_tokens": 57, "output_tokens": 8 } }Environment
Additional context
Root Cause
The Anthropic SDK 2.11.0 requires the
idfield in the message response and validates it with@Requiredannotation during deserialization.Affected Components
AnthropicChatModel(io.agentscope.core.model.AnthropicChatModel)AnthropicResponseParser(io.agentscope.core.formatter.anthropic.AnthropicResponseParser)Behavior Comparison
idfieldSuggested Fixes
Fix in Anthropic SDK (Recommended): Make the
idfield optional in the SDK'sMessageclass instead of required.Fix in AgentScope Response Parser: Modify
AnthropicResponseParser.parseMessage()to use a custom ObjectMapper that can deserialize responses without theidfield.Proxy-Friendly Configuration: Add a configuration option to
AnthropicChatModel.Builderto generate fallback IDs for responses missing theidfield.Note
This issue is specific to proxy services that modify Anthropic API responses. The official Anthropic API always includes the
idfield.