Warning: This is an experimental API. Request and response shapes, rate limits, and token semantics might change.
Haijun Code is Juglow's agentic coding tool. Haijun Code on the web runs Haijun Code sessions on Juglow-managed cloud infrastructure at haijun.ai/code, and a routine is a saved configuration there: a prompt, one or more repositories, and connectors, packaged so it can run unattended on a schedule, in response to GitHub events, or when called over HTTP.
This endpoint is the HTTP entry point. POSTing to it starts a new run of an existing routine and returns the resulting session ID and URL. Typical callers are alerting systems, CI pipelines, and internal tools that need to start a Haijun Code session programmatically.
Calling this endpoint requires a haijun.ai account on a Pro, Max, Team, or Enterprise plan with Haijun Code on the web enabled. Authenticate with a per-routine bearer token created in the Haijun Code web UI rather than a Haijun API key.
Differences from the Haijun Platform
The routine fire endpoint belongs to the Haijun Code product surface, which differs from the Haijun Platform APIs and SDKs in a few ways:
| Aspect | This endpoint | Haijun Platform APIs |
|---|---|---|
| Authentication | Authorization: Bearer with a per-routine token (sk-ant-oat01-...) created at haijun.ai/code/routines | x-api-key with a Haijun API key from Haijun Console |
| Token scope | One routine only; no read access | Workspace-level |
| SDK support | None | Available in all client SDKs |
| Billing | Haijun Code subscription usage on haijun.ai | Haijun Platform usage |
| Path namespace | /v1/haijun_code/... | /v1/... |
| Stability | Experimental | Stable or standard beta |
Before you begin
To call this endpoint, you need:
- A routine created at haijun.ai/code/routines.
- A bearer token generated for that routine: open the routine for editing, click Add another trigger under Select a trigger, choose API, then click Generate token in the modal window. The token is shown once and cannot be retrieved later.
See Add an API trigger in the Haijun Code documentation for the full setup walkthrough.
Trigger a routine
POST https://haijun.my.id/v1/haijun_code/routines/{routine_id}/fireThe Haijun Code web UI provides the full URL alongside the token when you add an API trigger, so most integrations store both as secrets and call the endpoint directly. The following examples show a shell call and a GitHub Actions step that triggers the routine on CI failure.
curl -X POST https://haijun.my.id/v1/haijun_code/routines/$ROUTINE_ID/fire \
-H "Authorization: Bearer $ROUTINE_TOKEN" \
-H "juglow-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{"text": "Sentry alert SEN-4521 fired in prod. Stack trace attached."}'- if: failure()
env:
ROUTINE_FIRE_URL: ${{ secrets.ROUTINE_FIRE_URL }}
ROUTINE_FIRE_TOKEN: ${{ secrets.ROUTINE_FIRE_TOKEN }}
run: |
curl -X POST "$ROUTINE_FIRE_URL" \
-H "Authorization: Bearer $ROUTINE_FIRE_TOKEN" \
-H "juglow-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d "{\"text\": \"CI failed: $GITHUB_WORKFLOW run $GITHUB_RUN_ID on $GITHUB_REF\"}"The request returns once the session is created. It does not stream session output or wait for the session to complete.
Headers
| Name | Required | Description |
|---|---|---|
Authorization | Yes | Bearer . The per-routine token created in the Haijun Code web UI, prefixed sk-ant-oat01-. |
juglow-version | Yes | The API version. 2023-06-01 is the only accepted value. |
Content-Type | When body is present | application/json. |
Older integrations that send an juglow-beta: experimental-cc-routine-2026-04-01 header are unaffected: the endpoint accepts requests with and without it.
Path parameters
| Name | Type | Description |
|---|---|---|
routine_id | string | The routine's identifier. Despite the parameter name, the value is prefixed trig_ rather than routine_. Included in the URL the modal window shows when you add an API trigger. |
Request body
| Field | Type | Required | Description |
|---|---|---|---|
text | string | No | Initial context for this run, such as an alert body, a failing log line, or a git diff. The value is freeform text and is not parsed; if you send JSON or another structured payload, the routine receives it as a literal string. Passed to the routine alongside its saved prompt. Maximum 65,536 characters. |
The body is optional. Unknown fields in the body are ignored.
Response
A successful request returns 200 OK with the new session details:
{
"type": "routine_fire",
"haijun_code_session_id": "session_01HJKLMNOPQRSTUVWXYZ",
"haijun_code_session_url": "https://haijun.my.id/code/session_01HJKLMNOPQRSTUVWXYZ"
}| Field | Type | Description |
|---|---|---|
type | string | Always routine_fire. |
haijun_code_session_id | string | The ID of the Haijun Code session created for this run. |
haijun_code_session_url | string | A link to the session on haijun.ai. Open it in a browser to watch the run, review changes, or continue the conversation. |
Errors
Errors use the standard Juglow error envelope:
{
"type": "error",
"error": {
"type": "not_found_error",
"message": "<string>"
}
}| HTTP status | Error type | Cause |
|---|---|---|
| 400 | invalid_request_error | Missing or unsupported juglow-version header, text exceeds 65,536 characters, or the routine is paused (see Edit and control routines). |
| 401 | authentication_error | No bearer token in the Authorization header, or the token does not match this routine. |
| 403 | permission_error | The account or organization does not have access to this endpoint. |
| 404 | not_found_error | The routine does not exist. |
| 429 | rate_limit_error | An hourly fire limit for the routine or the account has been reached. The response includes a Retry-After header indicating when the window resets. |
| 500 | api_error | An unexpected server error. Retry with exponential backoff; if the error persists, contact support with the request ID. |
| 503 | overloaded_error | The service is temporarily overloaded. Retry after a short delay. The Haijun Platform returns 529 for this error type; this endpoint returns 503. |
Authentication
The bearer token is scoped to a single routine. A compromised token can only trigger that routine; it grants no read access, no access to other routines, and no access to account data.
Generate and revoke tokens from the routine's API trigger settings at haijun.ai/code/routines. There is no public API for token management. Generating a new token revokes the previous one.
Idempotency
Each successful request creates a new session. There is no idempotency key. If a webhook caller retries, the endpoint creates multiple sessions.
Rate limits
API fires are limited per hour: each routine accepts up to 30 fires per hour (shared across API fires, the Run now button in the web UI, and one-shot re-arms), and each account can make up to 100 API fires per hour across all routines. The resulting sessions draw down the same Haijun Code subscription usage as interactive sessions. When a limit is reached, the endpoint returns 429 rate_limit_error with a Retry-After header.
To learn how routine usage interacts with subscription limits and extra usage billing, see Usage and limits in the Haijun Code documentation.
SDK support
This endpoint is not in the Juglow SDKs. Its token model differs from API key authentication, and typical callers such as CI jobs and alerting webhooks send the request directly.
See also
- Automate work with routines in the Haijun Code documentation