Prerequisites
- An API key ID and secret with Agent API access (contact support to enable it)
- A credit balance — agent turns and the generations they run are billed to your account
Use the SDK
Install Python SDK 0.2.0 or later:agents namespace covers the whole flow. run() sends the task and polls with backoff until the turn ends, so one call returns the finished answer:
Python
SyncClient() also reads credentials from HF_KEY or the pair HF_API_KEY and HF_API_SECRET. AsyncClient exposes the same agent methods; await each call. on_question is a synchronous callback returning an answer string for both clients.
Python run() polls with backoff from 2 to 10 seconds and waits up to 30 minutes by default. Override the wait limit with run(..., timeout=seconds). If the limit is reached, it raises AgentTimeoutError; the server-side turn keeps running. Read its messages or explicitly call sessions.interrupt() to request that it stop.
TypeScript
Install JS SDK 0.2.4 or later and use the recommended@higgsfield/client/v2 entry point:
TypeScript
higgsfield.agents after config({ credentials: 'key-id:key-secret' }). Import both from @higgsfield/client/v2. Explicit clients created with configuration keep their credentials separate.
TypeScript run() takes timeout in milliseconds (default: 30 minutes). Its onQuestion handler can return a string or a promise of one. A timeout stops the local wait while the server-side turn continues, just as in Python.
Errors are typed: a busy session raises SessionBusyError (a turn is already running — one turn per session at a time), missing access raises AgentAccessDeniedError, and an exhausted balance raises InsufficientCreditsError in Python or NotEnoughCreditsError in TypeScript. Lower-level methods (sessions.send, sessions.messages, sessions.interrupt) are available when you want to drive the poll loop yourself.
Use cURL
The same flow over raw REST — useful to understand what the SDK does. You’ll needcurl and jq.
1. Configure credentials
2. Create a session
session_id and reuse it — the agent remembers previous turns.
3. Send a task
202 and the turn runs asynchronously. If the session is already running a turn you get 409 session_busy.
4. Poll for the result
"status": "completed". A simple turn finishes in under a minute; a turn with several generations can take considerably longer.
message is a structured object; the answer text lives in its parts array. To extract it:
5. Continue the conversation
The session keeps memory. Send a follow-up the same way:If the agent asks a question
When a task is ambiguous, the agent may ask for a decision instead of guessing. The session status becomesawaiting_input and the turn parks. Answer with a regular message — your reply resumes the same turn:
Next steps
- API reference — all endpoints, media uploads, interrupts, errors, and billing.
- Agent overview — what the agent can and cannot do.