Bug
The helper function BetaManagedAgentsEventParamsOfUserMessage() in betasessionevent.go does not set the required Type field on BetaManagedAgentsUserMessageEventParams, resulting in a 400 Bad Request with events[0].type: Field required when calling POST /v1/sessions/{id}/events.
Reproduction
client.Beta.Sessions.Events.Send(ctx, sessionID, anthropic.BetaSessionEventSendParams{
Events: []anthropic.BetaManagedAgentsEventParamsUnion{
anthropic.BetaManagedAgentsEventParamsOfUserMessage(
[]anthropic.BetaManagedAgentsUserMessageEventParamsContentUnion{{
OfText: &anthropic.BetaManagedAgentsTextBlockParam{
Text: "hello",
Type: anthropic.BetaManagedAgentsTextBlockTypeText,
},
}},
),
},
})
Returns:
400 Bad Request: {"type":"error","error":{"type":"invalid_request_error","message":"Failed to parse request: events[0].type: Field required"}}
Root cause
The helper only sets Content, not Type:
func BetaManagedAgentsEventParamsOfUserMessage(content []BetaManagedAgentsUserMessageEventParamsContentUnion) BetaManagedAgentsEventParamsUnion {
var userMessage BetaManagedAgentsUserMessageEventParams
userMessage.Content = content // ✅
// userMessage.Type is never set ❌
return BetaManagedAgentsEventParamsUnion{OfUserMessage: &userMessage}
}
Compare with the other helpers which DO accept and set their type parameter:
func BetaManagedAgentsEventParamsOfUserInterrupt(type_ ...) { ... userInterrupt.Type = type_ ... }
func BetaManagedAgentsEventParamsOfUserToolConfirmation(result, toolUseID, type_ ...) { ... userToolConfirmation.Type = type_ ... }
Suggested fix
Either set the type automatically (since there's only one valid value):
func BetaManagedAgentsEventParamsOfUserMessage(content []BetaManagedAgentsUserMessageEventParamsContentUnion) BetaManagedAgentsEventParamsUnion {
var userMessage BetaManagedAgentsUserMessageEventParams
userMessage.Content = content
userMessage.Type = BetaManagedAgentsUserMessageEventParamsTypeUserMessage
return BetaManagedAgentsEventParamsUnion{OfUserMessage: &userMessage}
}
Workaround
Construct the struct directly instead of using the helper:
Events: []anthropic.BetaManagedAgentsEventParamsUnion{
{
OfUserMessage: &anthropic.BetaManagedAgentsUserMessageEventParams{
Content: content,
Type: anthropic.BetaManagedAgentsUserMessageEventParamsTypeUserMessage,
},
},
},
Version
anthropic-sdk-go v1.34.0
Bug
The helper function
BetaManagedAgentsEventParamsOfUserMessage()inbetasessionevent.godoes not set the requiredTypefield onBetaManagedAgentsUserMessageEventParams, resulting in a400 Bad Requestwithevents[0].type: Field requiredwhen callingPOST /v1/sessions/{id}/events.Reproduction
Returns:
Root cause
The helper only sets
Content, notType:Compare with the other helpers which DO accept and set their type parameter:
Suggested fix
Either set the type automatically (since there's only one valid value):
Workaround
Construct the struct directly instead of using the helper:
Version
anthropic-sdk-go v1.34.0