API Endpoint Verification Guide
Overview
This document explains how to verify that the api_name="safe_gpu_chat_handler" endpoint is properly deployed and running.
Implementation Status
β
Code Deployed: The API endpoint registration code is present in app.py:
- Line 845:
api_name="safe_gpu_chat_handler"is set on theapi_message.submit()event - Line 849: Log message confirms registration
- Lines 1899-1900, 2002-2003: Handler functions are initialized and set globally
- Lines 2073-2097: Verification logging on app startup
Verification Methods
1. Check Application Logs
When the application starts, you should see these log messages:
============================================================
VERIFYING API ENDPOINTS
============================================================
β API is enabled in Gradio config: True
Registered API endpoints:
- /api/safe_gpu_chat_handler (POST)
- /api/new_session (POST)
- /api/update_session_info (POST)
...
β API handler function initialized: True
Handler type: function
============================================================
LAUNCHING GRADIO APP
============================================================
API endpoints available at: http://<host>:7860/api/
Additionally, during interface creation:
β API endpoint '/api/safe_gpu_chat_handler' registered with api_name
β GPU chat handler initialized and set as API handler
OR
β Non-GPU chat handler initialized and set as API handler
2. Use the Verification Script
Run the verification script to test the endpoint:
python verify_api_endpoint.py [base_url]
Example:
# Local testing
python verify_api_endpoint.py http://localhost:7860
# HuggingFace Spaces
python verify_api_endpoint.py https://jatinautonomouslabs-research-ai-assistant.hf.space
The script will:
- Check if Gradio API info is accessible
- Verify the endpoint is registered
- Test actual endpoint accessibility
- Return exit code 0 if successful
3. Manual HTTP Test
Test the endpoint directly using curl or HTTP client:
curl -X POST http://localhost:7860/api/safe_gpu_chat_handler \
-H "Content-Type: application/json" \
-d '{
"data": [
"test message",
[],
"Admin_J",
"Session: test123 | User: Admin_J | Interactions: 0"
]
}'
Expected responses:
- 200 OK: Endpoint is working correctly
- 422 Validation Error: Endpoint exists but validation failed (still confirms deployment)
- 404 Not Found: Endpoint not registered
4. Check Gradio API Documentation
Visit the Gradio API documentation page:
- Local:
http://localhost:7860/docsorhttp://localhost:7860/api/docs - Spaces:
https://<your-space>.hf.space/docs
Look for /api/safe_gpu_chat_handler in the list of available endpoints.
5. Inspect Gradio Config
If you have access to the running instance, check:
import gradio as gr
# After demo is created
demo.config.api_open # Should be True
demo.config.show_api # Should be True
Code Location Reference
| Component | File | Line(s) |
|---|---|---|
| API Endpoint Registration | app.py |
838-849 |
| Handler Initialization (GPU) | app.py |
1899-1900 |
| Handler Initialization (Non-GPU) | app.py |
2002-2003 |
| Startup Verification | app.py |
2073-2097 |
| Global Handler Variable | app.py |
27-28 |
Troubleshooting
Issue: Endpoint not found (404)
Check:
- Application logs show "API endpoint registered" message
show_api=Trueis set indemo.launch()(line 2108)- Handler function is initialized (check logs for handler type)
Solution:
- Ensure
api_nameparameter is correctly set on the submit event - Verify the handler function is defined before the interface is created
Issue: Handler function is None
Check:
- Logs show handler initialization message
_api_chat_handler_fnis set after handlers are defined
Solution:
- Verify GPU availability check runs correctly
- Check that handler functions are defined (lines 1779-1997)
Issue: Endpoint accessible but returns errors
This is expected - The endpoint is deployed correctly. The errors are validation or processing errors, not deployment issues.
Expected Behavior
β Deployed Successfully:
- Application logs show registration messages
- HTTP requests to
/api/safe_gpu_chat_handlerreturn 200 or 422 (not 404) - Verification script passes
- Handler function is not None
β Not Deployed:
- 404 errors on endpoint access
- Logs don't show registration messages
- Handler function is None
Additional Notes
- The endpoint uses hidden Gradio components (visible=False) to avoid UI interference
- The handler automatically selects GPU or non-GPU handler based on availability
- Fallback to
process_messageensures endpoint always works - All API endpoints are registered with
api_nameparameters for REST access