Skip to main content
POST /v1/agent/invoke Send a message to an agent from your own app or service.

Authentication

Send your workspace API key in the Authorization header.
Agent webhook triggers use the agent webhook secret instead of an API key. See Webhook trigger.

Request body

Open an agent in the editor and click Code Snippet to see the current public request shape in Fetch Hive.

Webhook trigger

POST /v1/agent/webhooks/{agent_id} Use an agent webhook trigger when an external service should start an agent run without a workspace API key. The request must include the agent webhook secret in X-Fetch-Hive-Webhook-Secret. If a third-party tool cannot set custom headers, use ?secret=YOUR_WEBHOOK_SECRET as a fallback. Agent webhook triggers always use callback delivery. Include async.callback_url; Fetch Hive returns 202 with request_id and run_status: "running", then delivers agent.completed, agent.failed, or agent.awaiting_approval to the callback URL.
message is required. thread_id is optional and can be reused to resume a caller-managed thread. metadata follows the same flat scalar-only rule as normal agent invokes and appears in log filtering. Add response_format to the webhook body to get JSON back. It is the same object as the JSON output field on invoke, and it applies to this call only. Omit it and the callback carries text.
agent.completed keeps data.response as the JSON text and adds data.output_json, the parsed object. output_json is not sent on agent.awaiting_approval or agent.failed.
If the schema is invalid, the model cannot return JSON Schema, or the answer still does not match after one retry, the run fails and Fetch Hive delivers agent.failed with the error in data.error. Fetch Hive signs the outbound callback with the same webhook secret used for inbound trigger authentication. Callback data contains response on agent.completed and error on agent.failed; use the top-level event_type and request_id for terminal state and correlation. agent.awaiting_approval includes pending_tool_approvals and a dashboard review_url. A later agent.completed includes resumed_from_run_id when the run continued after approval. See Tool approvals. metadata must be a flat object. Keys must be non-empty strings, and values must be strings, numbers, booleans, or null. Arrays and nested objects are rejected before the run starts. attachments items can be simple URL strings:
They can also use this object shape when you want to provide metadata:
Only https:// URLs are accepted. Up to five attachments are allowed per message. Document attachments are exposed to the agent through the system read_file tool as an <available_files> manifest; the agent calls read_file before relying on document contents. Image attachments are sent to the model as multimodal input. For image URLs without a file extension, use the object shape with file_type set to an image MIME type (for example image/png). If an attachment URL or type is invalid, Fetch Hive returns 422 Unprocessable Entity instead of opening the stream. Supported document attachments:
  • CSV: text/csv, .csv
  • XLSX: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, .xlsx
  • PDF: application/pdf, .pdf
  • DOCX: application/vnd.openxmlformats-officedocument.wordprocessingml.document, .docx
  • Text and Markdown by extension: .txt, .md, .markdown
For extensionless URLs, such as Fetch Hive Media Library URLs, pass the URL directly. Fetch Hive allow-lists the URL for read_file, and the file tool detects the actual type when it fetches the file. Valid:
Invalid:
The code snippet dialog uses this body shape:
When using thread_id for persistent conversations:
When using messages for caller-managed (stateless) history:
If a previous assistant turn generated a file, pass that file back on the relevant history message through messages[].attachments. Fetch Hive uses the structured attachment URLs in current and historical messages to authorize read_file access for follow-up turns; URLs mentioned only in plain text are not treated as file-tool attachments.

Auto-approve for one call

tool_approval: "auto_approve" is accepted only from an API key whose owner or admin has turned on “Allow this key to auto-approve actions” in Settings → API keys. The call does not change the agent’s saved setting and does not write a policy. A key without that permission, a signed-in editor token, and a webhook all return 403 before any model call, preflight, or billing:
When auto-approve is turned off for the workspace, the same error_code is returned with the message Auto-approve is not available for this workspace. Destructive actions still ask. Deny rules still block the action. A sub-agent started by this call receives the same tool_approval and the same API key. A workflow the agent starts does not. A successful response echoes tool_approval as auto_approve or policy. When an action ran because of an override, the body also includes auto_approved_tool_calls: [{ "summary": string, "tool_name": string }]. A streaming call puts both fields on the final usage event.

JSON output

response_format belongs to this call. Omit it and the agent returns text. Send a schema and the same agent returns JSON.
type is json_schema or text. The schema root must be an object. The schema document must be at most 100000 bytes. When strict is omitted or true, each object node is stored with additionalProperties: false. strict: false leaves the schema as you sent it. Older clients may send is_json_schema_response_format: true plus json_schema instead. When both shapes are present, response_format wins. A model that does not support JSON Schema returns 422 json_schema_unsupported before the run starts. A schema that is not an object, or is larger than 100000 bytes, returns 422 json_schema_invalid. The schema applies to the final answer. Tool calls still run. If that answer does not match the schema, Fetch Hive asks for the answer once more. A second failure returns 422 json_schema_output_invalid. The message saved on the thread is the JSON text. A non-streaming response keeps response as that JSON text and adds output_json, the parsed object. A streaming call still sends text deltas as they arrive. The final usage event includes output_json. Use output_json when a repair replaced the text after those deltas. response_format also works on agent webhook triggers. The callback then carries output_json on agent.completed.

Response

If streaming is true, Fetch Hive returns a stream of events. If the provider fails after the stream has opened, Fetch Hive sends a final error event before closing the stream. If the client disconnects first, Fetch Hive treats it as a silent cancellation and does not create a failed agent run, bill usage, or report a provider-error event unless the provider had already completed and usage was committed. Example reasoning event:
Example response event:
Example tool event:
Example final usage event:
Example tool approval event:
Example final usage event when waiting for approval:
status and run_id are always present. thread_id is the value you sent, or null. pending_tool_approvals is present only when status is awaiting_approval. denied_tool_calls is present only when a policy denied a call in the turn. stop_reason stays the provider value. See Tool approvals. Example error event:
If streaming is false, Fetch Hive returns one JSON response. Provider execution failures return 502 Bad Gateway with an error message.
A paused non-streaming response uses the same pending_tool_approvals shape as the usage event above, and the response text includes [Waiting for approval: …].

Example