FastAPI service that implements the same HTTP contract as Flow2API’s remote_browser client (/api/v1/solve, etc.) and accepts WebSocket connections from user machines at /ws/agents.
- In-process only: connected-agent pool dispatch (no token_id routing).
- Redis is in
docker-compose.agent.yml(merge withdocker-compose.yml); the gateway MVP does not require Redis logic yet. - Optional Pydantic shapes:
schemas.py.
export GATEWAY_FLOW2API_BEARER=your-secret # must match Flow2API remote_browser_api_key
export GATEWAY_FLOW2API_BEARER_PREVIOUS=old-secret # optional during rotation window
export GATEWAY_AGENT_AUTH_MODE=legacy # legacy | keygen | dual
export GATEWAY_AGENT_DEVICE_TOKEN=agent-secret
python -m src.agent_gatewayHealth: GET http://127.0.0.1:9080/health
See ../../docs/agent-gateway.md.
- Connect to
ws://<host>:9080/ws/agents. - Send one JSON line (
register) in one of these modes:- Legacy:
{"type":"register","device_token":"<GATEWAY_AGENT_DEVICE_TOKEN>"} - Keygen (jwt):
{"type":"register","agent_token":"<keygen-token>"} - Keygen (introspection):
{"type":"register","agent_token":"<keygen-token>","agent_token_id":"<keygen-token-uuid>"}
- Legacy:
- Receive
solve_jobmessages; reply withsolve_resultorsolve_error:
{"type":"solve_result","job_id":"...","token":"...","session_id":"...","fingerprint":{}}{"type":"solve_error","job_id":"...","error":"reason"}Set GATEWAY_AGENT_AUTH_MODE=keygen (or dual during migration) and configure:
KEYGEN_VERIFY_MODE=jwt|introspectionKEYGEN_PUBLIC_KEY(jwt mode) orKEYGEN_API_TOKEN+KEYGEN_API_URL(introspection mode)KEYGEN_ACCOUNT(required for account-scoped introspection)
In Keygen mode, each agent sends agent_token and receives registered with identity metadata.
Auth boundary reminder:
- Keygen secures WS agent identity (
/ws/agents). - HTTP
/api/v1/*is still protected byGATEWAY_FLOW2API_BEARER.