The TypeScript SDK (Documentation Index
Fetch the complete documentation index at: https://docs.phrony.com/llms.txt
Use this file to discover all available pages before exploring further.
@phrony/sdk) wraps the same REST routes documented in the API Reference. It sets X-API-Key, maps methods to paths, and ships types for common responses (including the conversation payload).
Requirements: Node 18+, or any JavaScript environment that provides fetch (browsers, Deno, Bun, and so on).
Source code: the package is open source on GitHub (MIT). Report issues and contribute there.
Install
npm or yarn if your project standardizes on those.
Create a client
You need a workspace API key with prefixphk_, scoped to the same agent and API trigger as the requests you make.
| Option | Default | Purpose |
|---|---|---|
apiKey | (required) | The secret key string |
baseUrl | https://api.phrony.com | Your team’s base URL, if it differs; use the value from the agent’s Access tab in the Phrony dashboard |
fetch | globalThis.fetch | Override for tests, old Node, or custom stacks |
How it maps to the API
| SDK method | HTTP |
|---|---|
startRun | Start a run POST /v1/agents/{agentId}/runs |
listSessions | List sessions GET /v1/agents/{agentId}/sessions |
getRun | Get run status GET /v1/runs/{runId} |
getConversation | Get conversation GET /v1/runs/{runId}/conversation |
sendRunMessage | Send input or messages POST .../messages or .../input |
streamRunEvents | Stream (SSE) GET /v1/runs/{runId}/stream |
presignFile / finalizeFile | File library POST /v1/file-library/... |
uploadWorkspaceFile | Presign → PUT → finalize in one call |
Start a run
input must match your deployed agent version input contract. Pass {} or omit the shape the agent does not use.
runId.
Get the agent’s answer
After the run has finished (or you only need the latest known fields), readoutput (and optional error) from get run status.
output (and the merged timeline) from getConversation on the session object, the runs[] entries, or completion rows in items (for example RunCompleted / SessionCompleted).
List sessions
Conversation and timeline
getConversation returns session, runs, and merged items (steps and synthetic rows). With stepContent: "slim", redundant keys in step content objects can be omitted—see the Runs API description.
The SDK exports types such as ConversationResponse, ConversationSession, ConversationRunSummary, and ConversationTimelineItem, plus narrower content shapes for common step type values (for example ToolCall, Reasoning, UserTaskReq).
Follow-up messages, HITL, and user tasks
sendRunMessage sends runId for you. Add userTaskId, approved, text, files, and other fields as required for your run’s pause type—see Send input or messages to a run.
.../input path instead of .../messages, pass { path: "input" } as the third argument.
Stream (SSE)
streamRunEvents parses Server-Sent Events and yields a JSON object per event (ts, kind, subject, data). Use it from a server or a runtime with streamable fetch; the browser’s EventSource cannot set X-API-Key.
File library
The key must have Allow file uploads.uploadWorkspaceFile runs presign, upload, and finalize. Use fileRefFromObjectKey (or a files[] attachment on a message) as in the File library examples.
Errors
Failed HTTP status codes throwPhronyAPIError with status, path, and the response body (often JSON text).
Further reading
- npm:
@phrony/sdk - Readme and advanced usage (including a full method table) live in the repository
- Academy example — Hands-on flow using the same package