Create a credential
In n8n, go to Credentials → Add Credential → Header Auth and set:
Create the key at platform.hcompany.ai/settings/api-keys. It’s shown once, so copy it when you create it. A key is scoped to one organization.
Start a session
Add an HTTP Request node:
Body:
Request body
h/web-surfer-flash is a built-in agent that comes with its own browser environment, so you can run a task without setting anything else up. To run your own agent, pass its name instead, or send an inline agent object. See Create a session for the full body.The response returns the session id you’ll use to poll for results:Response
Poll for completion
Add a second HTTP Request node in a loop:
Check the
status field. The session is done when status is completed, failed, timed_out, or interrupted. Any other value (queued, pending, running, paused, idle, awaiting_tool_results) means it’s still going. Use an If node to branch on the status, and loop the “still running” branch back through a Wait node before hitting the status endpoint again. Two to five seconds is a good interval. Back off to ten to fifteen for tasks that run several minutes.Status response
Import the full workflow
Rather than build the four nodes by hand, copy the JSON below and paste it onto an empty n8n canvas (or ⋯ menu → Import from clipboard). It wires the steps as a loop:- Wait pauses a few seconds.
- Poll Status checks the state.
- If reads the answer once the status is terminal, or loops back to Wait.
n8n workflow JSON
n8n workflow JSON
Event-driven alternative
Instead of polling, use Webhooks to get a callback when a session changes status.1
Add a Webhook trigger node in n8n
Copy its Production URL.
2
Register the URL
Call the Create webhook API with that URL for your organization. Subscribe to
session.completed and session.failed, or to session.status_updated for every transition (see the event catalog).3
Handle the delivery
n8n receives a
POST whenever a matching event fires, with session_id, status, and previous_status in the payload. Deliveries are signed and retried with backoff, so the same event can arrive more than once: verify the signature (see Verifying deliveries), skip event ids you’ve already processed, and fetch the session for the authoritative state.Next steps
Create a session
The full session request body and options.
Session status
States, step count, and the polling pattern.
Webhooks
Signed callbacks on status changes, and how to verify them.
SDKs
The typed Python and TypeScript clients and the hai CLI.