Overview
APITHON offers two distinct operational modes to suit different use cases. After successful protocol synchronization, you can choose between:- Gateway Mode - REST API server with OpenAI-compatible endpoints
- Chat Mode - Interactive command-line shell for direct communication
Both modes share the same underlying protocol communication engine (
ejecutar_request_protocolo) and use the synchronized session data captured during initialization.Mode Selection
After the tunnel synchronization completes successfully (SESS["status_ready"] = True), you’ll see the mode selection menu:
apithon.py:188-193
Gateway Mode (Option 1)
When to Use Gateway Mode
Gateway mode is ideal when you need to:- Integrate with external tools - Connect LangChain, automation scripts, or third-party applications
- Build programmatic workflows - Automate queries through standard REST API calls
- Enable multi-device access - Expose the API across your local network
- Maintain persistent service - Keep the gateway running continuously for repeated requests
- Use OpenAI-compatible clients - Leverage existing tools that support the
/v1/chat/completionsformat
How Gateway Mode Works
Network Configuration
After selecting Option 1, you choose your network scope:
- L (Localhost): Binds to
127.0.0.1- accessible only from the host machine - N (LAN): Binds to
0.0.0.0- accessible from any device on your network
apithon.py:196-206Flask Server Initialization
A Flask application starts on port 5000, exposing the Source Reference:
/v1/chat/completions endpoint:apithon.py:132-139API Format
Authentication
Bearer token authentication. Default API key:
UnHackerEnCapitalSource: apithon.py:29 (API_KEY_GATEWAY)Request Format
The gateway extracts the content from the last message in the array:
request.json.get("messages", [{}])[-1].get("content", "")Response Format
Platform-Specific Examples
Python Integration Example
Chat Mode (Option 2)
When to Use Chat Mode
Chat mode is ideal when you need to:- Perform quick manual tests - Rapidly test queries without API overhead
- Debug protocol responses - Examine raw response data directly
- Conduct interactive analysis - Have a conversation-style workflow
- Avoid API complexity - Skip authentication and request formatting
- Work in terminal environments - Stay within the command-line interface
How Chat Mode Works
When you select Option 2, APITHON enters an interactive shell loop:apithon.py:170-176
Interactive Shell Features
Direct Communication
Queries are sent immediately through
ejecutar_request_protocolo() without any API layerReal-time Responses
Responses are printed directly to stdout with streaming indicator (
flush=True)Simple Exit
Type
salir or exit to cleanly terminate the sessionSession Persistence
Uses the same synchronized session data throughout the conversation
Example Session
Mode Comparison
Architecture Differences
Architecture Differences
| Aspect | Gateway Mode | Chat Mode |
|---|---|---|
| Entry Point | Flask HTTP server | Direct Python function |
| Authentication | Bearer token required | No authentication |
| Format | JSON request/response | Plain text input/output |
| Threading | Runs in daemon thread | Runs in main thread |
| Termination | Ctrl+C (KeyboardInterrupt) | Type ‘salir’ or ‘exit’ |
Performance Characteristics
Performance Characteristics
Gateway Mode:
- Additional HTTP parsing overhead
- Better for concurrent requests (Flask handles multiple connections)
- Persistent service - runs indefinitely
- Network latency depends on LAN/localhost configuration
- Direct function call - minimal overhead
- Sequential processing only (one query at a time)
- Session ends when user exits
- No network overhead
Protocol Communication Layer
Protocol Communication Layer
Both modes use the exact same underlying protocol engine:Source Reference:
apithon.py:103-129The only difference is how user input arrives and how responses are delivered.Switching Between Modes
Session Data Shared Across Modes
Both modes rely on the globalSESS dictionary populated during tunnel synchronization:
apithon.py:31-38
Key InsightBecause both modes share session data, your choice of mode doesn’t affect the capability or response quality - only the interface for interaction.