-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Needs ReproductionWhen an issue is not reproducible as of nowWhen an issue is not reproducible as of now
Description
Bug Description
wrapClaudeAgentSDK produces tool_use.id values that do not match the Anthropic API's required pattern ^[a-zA-Z0-9_-]+$, causing 400 errors when the wrapped SDK sends requests through OpenRouter.
Error
API Error: 400
{
"error": {
"message": "Provider returned error",
"code": 400,
"metadata": {
"raw": "{\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.1.content.1.tool_use.id: String should match pattern '^[a-zA-Z0-9_-]+$'\"}}"
}
}
}
Reproduction
import { wrapClaudeAgentSDK, initLogger } from 'braintrust'
import * as claudeSDK from '@anthropic-ai/claude-agent-sdk'
initLogger({ projectName: 'MyProject', apiKey: '...' })
const { query } = wrapClaudeAgentSDK(claudeSDK)
// Configure SDK to use OpenRouter as proxy
const result = query({
prompt: 'Hello',
options: {
env: {
ANTHROPIC_AUTH_TOKEN: '<openrouter-key>',
ANTHROPIC_API_KEY: '',
ANTHROPIC_BASE_URL: 'https://openrouter.ai/api',
},
mcpServers: { /* ... */ },
maxTurns: 20,
},
})Every request fails with the above tool_use.id validation error.
Workaround
Exporting the raw SDK without wrapping resolves the issue:
// export const claudeAgent = wrapClaudeAgentSDK(claudeSDK) // ❌ broken
export const claudeAgent = claudeSDK // ✅ worksEnvironment
braintrust: 2.2.0@anthropic-ai/claude-agent-sdk: 0.2.29- API endpoint: OpenRouter (
https://openrouter.ai/api) - Runtime: Bun 1.3.x
Analysis
It appears that wrapClaudeAgentSDK intercepts or regenerates tool_use.id values using characters (likely .) that are outside the allowed pattern ^[a-zA-Z0-9_-]+$. The Anthropic API (via OpenRouter) then rejects these IDs during validation.
The raw SDK without wrapping generates valid toolu_* format IDs and works correctly.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Needs ReproductionWhen an issue is not reproducible as of nowWhen an issue is not reproducible as of now