This example demonstrates how to use Human Layer's API with simple curl commands to create and check function call approvals.
curljq(for JSON parsing)- Valid
HUMANLAYER_API_KEYenvironment variable set with your API key from Human Layer
to create an approval request, run a curl like:
curl -X POST https://api.humanlayer.dev/humanlayer/v1/function_calls \
-H "Authorization: Bearer ${HUMANLAYER_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"run_id": "curl-example",
"call_id": "1234-5678-...",
"spec": {
"fn": "send_email",
"kwargs": {
"to": "user@example.com",
"subject": "Hello",
"body": "This is a test email"
}
}
}'Test the context size limit by sending a large payload:
export HUMANLAYER_API_KEY=<your-api-key>
make test-large-contextThis will send a function call with a large array in the state field to test the context size limits.
Create a new function call approval request:
export HUMANLAYER_API_KEY=<your-api-key>
make create-approvalThis will create a new approval request with a randomly generated UUID. The output will look like:
{
"run_id": "curl-example",
"call_id": "1234-5678-...",
"spec": {
"fn": "send_email",
"kwargs": {
"to": "user@example.com",
"subject": "Hello",
"body": "This is a test email"
}
},
"status": {
"approved": false,
"comment": null
}
}Check the status of your approval request, using the call_id from the approval request:
make check-approval random_id=1234-5678-...If not yet approved, you'll see:
{
"run_id": "curl-example",
"call_id": "1234-5678-...",
"spec": {
"fn": "send_email",
"kwargs": {
"to": "user@example.com",
"subject": "Hello",
"body": "This is a test email"
}
},
"status": {
"approved": false,
"comment": null
}
}Once approved:
{
"run_id": "curl-example",
"call_id": "1234-5678-...",
"spec": {
"fn": "send_email",
"kwargs": {
"to": "user@example.com",
"subject": "Hello",
"body": "This is a test email"
}
},
"status": {
"approved": true,
"comment": "Approved by reviewer"
}
}To create a request and wait for approval:
make run-agentThis will:
- Create an approval request
- Poll for approval status every 3 seconds
- Output the approval comment once approved
Example output while waiting:
waiting for approval
waiting for approval
waiting for approval
Once approved:
approval granted with comment "Approved by reviewer"