This walkthrough goes from zero to a working API integration: you configure an agent in the Phrony dashboard, then drive it from your backend withDocumentation Index
Fetch the complete documentation index at: https://docs.phrony.com/llms.txt
Use this file to discover all available pages before exploring further.
X-API-Key. It also covers human-in-the-loop (HITL)—pausing for approval or input—and how to respond to user tasks with the same API instead of only in the dashboard.
You should already have a workspace, an LLM provider, and permissions to create agents and API keys.
What you will set up
| In the Phrony dashboard | In your code |
|---|---|
| Agent, deployed version, API trigger, API key scoped to that agent + trigger | POST to start a run, GET to poll, optional GET conversation |
| Optional: HITL execution mode and an integration operation with Require approval (HITL) | When the run waits, GET conversation to read user_task_id, then POST to resume with userTaskId + approved (or other fields) |
@phrony/sdk) so you do not hand-author every fetch call.
Part 1 — Create the agent and API access in the dashboard
1. Create or open an agent
In the Phrony dashboard, open your workspace and go to Agents. Create an agent or pick an existing one. Give it a clear name; you will reference it by id in code.2. Configure a version you can deploy
Open the Versions (or Editor) area for that agent and add a version:- Choose a model and prompt appropriate to your use case.
- Under Integrations / operations, attach at least one tool the model can call. For a HITL demo, edit an operation and turn on Require approval (HITL) before execution (or the equivalent for that connector) so runs can pause until someone approves the call.
- Set execution mode to HITL if you want people in the loop on the main path (recommended for approval flows).
3. Deploy a version
Deploy the version so the platform has a fixed snapshot to run. API runs always use what is deployed, not a draft.4. Add an API trigger
Open Triggers on the agent and add a trigger of type API.- Note the trigger id (you will need it when scoping an API key).
- For HITL + API, set Expose step timeline to API clients to on. If this is off, external
GET .../conversationand.../streamcalls are redacted and you may not see user task steps or ids—so you cannot complete tasks from your integration. See Embedded agents — API redaction.
5. Create an API key
Go to Settings (workspace) → API keys (or your workspace’s API key page).- Create a key and copy the secret (prefix
phk_). Store it in a secret manager or environment variable—never expose it in a browser or mobile app. - Add a scope that includes this agent and this API trigger only.
- If you will use file uploads, enable Allow file uploads for the key.
https://api.phrony.com) and your agentId—match those in your code.
Part 2 — Start a run and read the result from code
Set environment variables (names are suggestions):| Variable | Value |
|---|---|
PHRONY_API_BASE | https://api.phrony.com (or your team’s base URL) |
PHRONY_API_KEY | Your phk_... key |
AGENT_ID | The agent UUID from the dashboard |
POST /v1/agents/{agentId}/runs and a JSON body shaped to your agent’s input contract, for example:
sessionId and runId from the 202 response.
3. Poll GET /v1/runs/{runId} until the run reaches a terminal state or a state that means “waiting for a person” (see Part 3). Use the same X-API-Key on every call.
Part 3 — HITL: discover a user task and respond with the API
When the model hits an operation that requires approval, the run pauses and Phrony creates a user task. Your backend can treat this like a second phase of the samerunId:
- Poll
GET /v1/runs/{runId}untilstatusindicates the run is waiting for input—common values includeWaitingForHITL,WaitingForAITL, andWaitingForResponse(your workspace may use the same strings in the public poll body). If the run finishes without a pause, there is no task to complete in that loop. - Fetch the timeline with
GET /v1/runs/{runId}/conversation(same API key). With Expose step timeline to API clients on, the JSON includes anitemsarray. Find the row whosetypeisUserTaskReq: the stepcontentincludes auser_task_id(snake_case in the payload) identifying the pending task. - Resume with
POST /v1/runs/{runId}/messages(or.../input) and a JSON body that includes:runId— same UUID as in the pathuserTaskId— the value fromcontent.user_task_idapproved—trueto approve the tool call,falseto reject (when the task is an approval-style HITL step)
selectedOptionId, textValue, numberValue). See Runs — Send input or messages.
- Poll
GET /v1/runs/{runId}again. The run may continue, pause again (another task), or complete.
WaitingForResponse, send text or message instead of userTaskId (see the same API reference section).
Example (TypeScript SDK) after you have runId and have called getConversation:
GET /v1/runs/{runId}/stream (SSE) if you prefer event-driven waiting instead of polling; the same Expose step timeline setting applies. See Runs — Stream (SSE) for the event shape.
Checklist
- Version deployed; API trigger created; API key scoped to that agent + trigger
- HITL demo: HITL mode + at least one operation with Require approval, if you want approval tasks
- For HITL over HTTP: Expose step timeline to API clients = on on the API trigger
- Your service stores
phk_securely and only calls the API from your backend - You handle both
WaitingForHITL-style and terminal run outcomes in a loop
Related
- Embedded agents — Wider context, file uploads, and redaction
- Human in the loop — HITL concepts and operation-level approval
- User task — Task kinds and how work appears in the product
- API Reference — Agents and Runs — Schemas, examples, conversation and stream
- TypeScript SDK —
Phronyclient, types, and install instructions for@phrony/sdk