How get a script's response_variable when invoked through the API?

I have a trivial test script that returns a dictionary via -stop’s response_variable. I can invoke it from another script and successfully get the returned value.

I’m invoking this script via the services api from an external app, and want to be able to retrieve the response_variable’s value in the response json. Unfortunately, I don’t see the value anywhere in the json response. Is there a way to achieve this?

I’m running the script synchronously (via /api/services/script/myfunc, rather than via api/services/script.turn_on), so I assume the script results should be available by the time the API request completes.

For completeness, here’s my test script:

sequence:
  - variables:
      ret:
        aaa: bbb
  - stop: ""
    response_variable: ret
alias: MYFUNC
description: ""
mode: single

And here’s my curl test command:

baseurl=xxx
token=xxx
curl -s\
    -H "Authorization: Bearer $token" \
    -H "Content-Type: application/json" \
    -X POST $baseurl/api/services/script/myfunc \
    | python3 -m json.tool