Skip to main content
AI agent tasks, including multi-step reasoning, document analysis, and model chains, can take anywhere from 30 seconds to several minutes. HTTP gateways on every cloud platform, including GMI, close connections that stay open too long and return a 504 Gateway Timeout to the caller. The fix is to decouple accepting the request from returning the result. A 504 from a slow task and a connection failure are two different problems. If your endpoint is unreachable, first check that ingress is enabled and networking is configured for your deployment. The async pattern below only helps when the request reaches your agent, but the work takes too long to finish inside the gateway window.

The async job pattern

Instead of holding the connection open, your agent should:
  1. Accept the request and immediately return a job_id.
  2. Run the task in the background.
  3. Let the caller poll a status endpoint until the result is ready.

Implementation

Python (FastAPI)

Node.js (Express)

Calling the endpoint

Persisting job state

GMI containers are stateless. If a container restarts, any in-memory job state is lost. For production, write the job state to an external store such as Redis or a database, and inject the connection credentials as Secrets in Step 4 of Register an agent.