I am using TMS AI Studio v1.7.4.0.
The content of the SystemRole property is never sent to the Anthropic API when
the service is Claude. No error, no warning: the request succeeds and the model
simply runs with no system prompt at all.
In BuildPostData, the block that builds the system message excludes Claude:
"if (FSystemRole.Text <> '') and (Service <> aiClaude) then"
That exclusion is correct, because the Anthropic Messages API rejects a
"system" role inside the messages array with HTTP 400:
"messages: Unexpected role "system". The Messages API accepts a top-level
'system' parameter, not "system" as an input message role."
The problem is that the alternative Anthropic requires was never implemented.
Unlike the OpenAI-style providers, Anthropic expects the system prompt as a
top-level parameter, sibling of "messages". The cDataClaude template has no
"system" field, and FSystemRole is not referenced anywhere else in the
request-building path, so for Claude the value never leaves the component.
- Possible FIX (I made an API Call with this fix and it worked correctly)
Add a slot to the template:
cDataClaude = '{' +
'"model": "%s",' +
'%s'+ // system prompt, top-level
'"messages": [ %s ],'+
...
Populate it in the aiClaude branch of BuildPostData:
AClaudeSystemRole := '';
if FSystemRole.Text <> '' then
AClaudeSystemRole := '"system": "' + JsonEncode(FSystemRole.Text) + '",';
And pass it in second position:
Result := string.Format(cDataClaude, [FSettings.ClaudeModel,
AClaudeSystemRole, AMessages, FAllTools.ToJSON(Service, Settings.WebSearch),
AParallel, ATemperature, AMaxTokens, AOptions, ACacheControl]);
I have applied this fix in our code and confirmed the request now succeeds with the "system"
field present.
Reference: Messages - Claude API Reference
One more thing, also related with Claude API. In the same aiClaude branch, the reasoning effort is emitted inside "thinking" instead of in the "output_config" parameter that Anthropic expects. I have not tested it and have no fix for this, because it does not affect our code, but I think it could be a related issued with Claude API calls.