New APINew API
User GuideInstallationAPI ReferenceAI ApplicationsSkillsHelp & SupportBusiness Cooperation

Task Plugin API v1 Reference

Manifest, context, lifecycle, native routes, host protocols, usage, artifacts, and streaming capabilities of task plugins.

Contract Status and Authoritative Sources

This repository marks API v1 as a contract that has not yet been officially released. New capabilities may still use apiVersion: 1, and older hosts may reject unrecognized fields. This page summarizes the contract; the complete signature and validation structure are subject to v1.d.ts, v1.schema.json and the original specification.

Manifest: meta

FieldTypeDescription
apiVersion1Contract version
keystringPlugin identifier, max 30 characters, consistent with marketplace directory name
namestringDisplay name
versionstringSemantic version, consistent with version directory
author{ name, url? }Author name is required, URL is HTTP(S) address; self-declared author information
modelsstring[]Declares supported models
fetchModeper_task / batchSingle-task or batch polling
descriptionLocalizedTextPlugin description; keep each locale within 80 columns, see Plugin summary length below
iconstringLobeHub icon name or text / text:<label>, remote URLs or inline images are not accepted
websitestringOptional plugin official website, must be a valid HTTPS URL if not empty
sortPriorityintegerDisplay sort order, larger value means higher priority; does not affect routing priority
baseUrlstringDefault upstream address usable by channel type 61
allowedHostsstring[]Additional hosts allowed to access beyond channel host, can include port
upstreams("vendor" | "new_api")[]Optional upstream kinds; vendor support is implied, while new_api enables binding to type-60 New API channels
authstring / objectnone, api_key, vertex_oauth or authentication object defined by specification
channelTypesnumber[]Adaptable legacy channel types; third-party plugins typically use key binding for type 61
scopeobjectModels and channel types a request processing plugin asks to handle
routesNativeRoute[]Plugin's own native routes
protocolsProtocolClaim[]Host protocol declarations
usageSchema / usageExamplesobject / arrayDefault usage fields and examples
usageProfilesarrayProvides complete usage schema and examples per model
requiredCapabilitiesstring[]Versioned capabilities that must be supported by the host
submitResponseTypesarrayUpstream submission response types, default ["json"], can declare "sse"

baseUrl must not contain credentials, query strings, or fragments, and must use an ASCII hostname; self-hosted HTTP or private addresses are allowed. allowedHosts uses host / host:port, without protocol or path, and the port will be part of the matching. The default address does not implicitly expand the set of allowed hosts.

Request processing

In meta.scope, models accepts up to 100 distinct names of 1 to 128 characters and channelTypes up to 64 distinct positive new-api channel type numbers. Supply at least one model or channel type. An empty or omitted list leaves that dimension unrestricted.

A hook on another host may receive ctx.client (the recognized application) and ctx.session (an object with id and turn). New API leaves both fields unset.

Provider routes

On a provider route with incoming_path set to /v1/responses, set converter to openai_responses_to_claude_messages to send an OpenAI Responses request to an Anthropic Messages upstream. For a standard Messages endpoint, set upstream_path to /v1/messages.

Localized Text

LocalizedText can use a string or a language map containing en. Strings will be normalized to an English map. The matching order is current language, primary language, English:

description: {
  en: "Video generation through the vendor API",
  zh: "通过厂商接口生成视频",
  "zh-TW": "透過廠商介面產生影片",
}

Text in plugin data should not be used as translation keys for the management frontend. Model names, field keys, and raw enum values must remain stable.

Plugin summary length

The plugin site's marketplace list shows meta.description on a single line under the plugin name and cuts off anything longer with an ellipsis. Keep each locale's summary within 80 columns, counting each Chinese, Japanese or Korean character and each full-width punctuation mark as two columns and any other character as one. That is about 40 Chinese characters or 80 English characters, which fits on one line of the plugin site's list in a desktop browser window. Narrower windows and phones show less.

  • Lead with the vendor or product and the main capability, so a shortened line still identifies the plugin.
  • Name the model family and the main capabilities instead of listing every model variant, mode, endpoint or billing detail. The usage guide covers those.
  • Check each translation on its own. English often needs more columns than Chinese for the same meaning.
  • For example, Shengshu Vidu video generation (text-to-video, image-to-video, first-and-last-frame, and reference-to-video) (108 columns) becomes Shengshu Vidu video generation from text, images, keyframes or references (73 columns). 快手可灵视频生成(文生视频、图生视频) uses 38 columns.
  • This is a writing recommendation. Hosts enforce only the 512-rune limit.

Lifecycle Hooks

ExportInputPrimary Return Content
buildSubmitRequestDriverContextHTTP request descriptor
parseSubmitResponsectx, { statusCode, headers, body }{ taskId, taskData?, immediate?, state? }
buildQueryRequestTaskQueryContextSingle-task query descriptor, per_task is required
parseTaskResultQuery context, body, { status, headers }Standardized status, optional progress/reason/result, etc.
buildBatchQueryRequestBatch context, task arrayBatch query descriptor, batch is required
parseBatchResultBatch context, body, HTTP infoArray of results, each containing taskId, batch is required

Every plugin exports meta. Task plugins, including batch plugins, also export buildSubmitRequest, parseSubmitResponse and parseTaskResult.

For submission, the host accepts every upstream 2xx status, including 200, 201 Created, and 202 Accepted, then calls parseSubmitResponse with { statusCode, headers, body }. Any other status fails submission with the upstream status and body before the hook runs.

Standard statuses include NOT_START, SUBMITTED, QUEUED, IN_PROGRESS, SUCCESS, FAILURE, UNKNOWN. Unknown statuses return UNKNOWN; unknown results should not be defaulted to in-progress.

During polling, upstream HTTP status also participates in host determination: 404/410 leads to failure and refund; 401/403, 429, 5xx, and transport errors accumulate polling failures. After reaching TASK_POLL_MAX_FAILURES (default 20), failure cleanup is initiated, and the task timeout mechanism remains the outer deadline.

Request and Query Context

DriverContext provides normalized requestBody, request headers, action, model / upstreamModel, channel baseUrl, authentication information, file references, public task ID, and optional originTasks.

TaskQueryContext reconstructs from saved tasks:

FieldMeaning
taskIdUpstream task ID
publicTaskIdNew API public task ID
model / upstreamModelUser model name and upstream model name after channel mapping
actionPersisted standardized operation
dataCurrent Task.Data snapshot
statePlugin's private cross-polling state
baseUrl / Auth fieldsCurrently used channel information

The query side does not have requestBody. The saved field name is data, there is no raw alias. If the parsing hook omits state, the original state is retained; it is only updated if explicitly returned. Request and state inputs should be treated as read-only and not rely on module global variables to save task data.

Hook arguments and results

Treat all hook arguments as read-only, including nested objects and arrays. Plain JSON inputs are passed without copying and converted when first read; other values are normalized through the host JSON codec. Assignments inside a hook affect only that call's view. Return the value the host should use, and declare json-clone@1 to use utils.json.clone(value) when a mutable, independent copy is needed.

Never keep arguments or their nested values in module variables after a hook returns. Runtimes are pooled across requests: retained references can expose data to a later request and keep the original data alive. Use returned state for data that must survive polling.

Host integrations must also treat passed values as immutable. Returning an input unchanged may return the original Go value; copy it before modifying it, including before replacing file placeholders. Concurrent mutation of a shared Go map can terminate the process. JavaScript-created integers return as int64, other numbers as float64; unchanged host values retain their Go types, so numeric consumers must accept all supported number types.

Optional usage and artifact hooks are detected once when the plugin loads. An export that is undefined at load time stays absent even if assigned later. Existing callable bindings remain live.

Upstream kinds and gateway connections

meta.upstreams accepts the distinct values vendor and new_api. Vendor support is implicit. Declare new_api to use a New API gateway with this plugin installed as the upstream. Type 60 binds plugins through setting.task_plugin_key or setting.task_extend_plugin_keys. Types 60 and 61 are reserved. Multiple plugins may list the same legacy channel type in channelTypes.

The host supplies ctx.upstream on DriverContext, TaskQueryContext, BatchQueryContext, and the buildContentRequest context as { kind: "vendor" } or { kind: "new_api" }. Treat a missing field as vendor. For new_api, construct the plugin's own native paths, such as /doubao/api/v3/... or /ali/api/v1/..., instead of copying vendor paths. No prefix change is needed when the paths already match native routes or the plugin uses only host protocols.

For type-60 channels, the host has already set authHeader to Bearer <channel key> and apiKey to the channel key; vendor OAuth/JWT authentication is not run. Submission parsers must accept the upstream plugin's native presentation, and queries use the public task ID returned by that gateway. upstreams is an additive API v1 extension: older hosts reject the unknown field, so upgrade the host before installation.

HTTP Descriptors and Files

Construction hooks return { url, method?, headers?, body?, ... }, which are validated and sent by the host. JSON is the default body type, and multipart can also be constructed via bodyType: "multipart" and parts.

Inbound body is uniformly parsed by the host into the following union type:

type RequestBody =
  | { kind: 'json'; value: unknown }
  | { kind: 'form'; fields: Record<string, readonly string[]> }
  | {
      kind: 'multipart';
      fields: Record<string, readonly string[]>;
      files: readonly FileReference[];
    }
  | { kind: 'none' };

Files are referenced into JavaScript only as { ref, field, filename, mimeType, size }; plugins cannot directly read file bytes. Multipart outbound uses parts[].fileRef; JSON outbound can embed placeholders, which the host replaces with encoded content:

{ __fileRef: "request_file:input_reference", encoding: "base64" }
{ __fileRef: "request_file:input_reference", encoding: "dataUrl", mimeType: "image/png" }

Placeholders can optionally have maxBytes; the host will still perform file size limits and total volume checks. References must not be treated as file paths.

A repeated field such as image[] can contain several files. Each file has its own ref: request_file:<field> for the first, then request_file:<field>#<index> (zero-based, so the second file uses #1). Copy the corresponding files[].ref into parts[].fileRef or the JSON placeholder; do not construct references by hand or collapse all files in one field into a single reference.

Native Routes and Host Protocols

Native Routes

meta.routes defines plugin-specific URLs, where function names point to synchronous functions within the native object:

routes: [
  {
    method: 'POST',
    path: '/vendor/jobs',
    type: 'submit',
    decode: 'create',
    render: 'created',
  },
  {
    method: 'GET',
    path: '/vendor/jobs/:task_id',
    type: 'query',
    render: 'status',
  },
];
  • submit / dynamic must specify decode and render; query only specifies render and cannot declare a decoder.
  • The default task parameter name for query is task_id, which can be specified via taskIdParam.
  • Decoders return { kind: "submit", model, action?, requestBody?, originTaskIds? } or a query intent.
  • routes[].models can restrict top-level models for submit/dynamic, but not for query; when models are nested within the vendor body, the decoder should determine them.
  • The host is responsible for authentication, ownership, and task persistence; renderers only handle external responses. Error messages thrown by hooks may be returned to the caller and should use readable error text without sensitive data.

Built-in and uploaded plugins both serve their declared paths and a copy under /{key}. For example, a plugin with key demo-task declaring POST /v1/systemone serves both /v1/systemone and /demo-task/v1/systemone. A path whose first segment is already the key or a proper prefix of it, such as /ali/... for alibaba, keeps that address without another copy.

A host route of the same HTTP method, including its trailing-slash redirect, takes precedence. The gateway also skips a top-level path whose first segment belongs to another plugin's key or a built-in plugin's own prefix. The /{key} address remains available, and the plugin list (GET /api/plugin/task) and detail report skipped declarations in skipped_routes, for example GET /v1/models. The host's Video retrieval and Gemini predictLongRunning routes have specific plugin handoffs described in the Manifest section.

Routes intersecting /v1/tasks, /assets, or reserved console paths fail compilation. Plugin keys must also avoid api, host route prefixes such as v1, v1beta, mj, pg, and dashboard, and built-in plugin prefixes. Conflicting keys are rejected during compilation or route registration.

originTaskIds uses public task IDs. After the host checks ownership and channel consistency, originTasks containing internal upstream IDs are injected into the driver; they are not passed to external renderers.

Result retention

routes[].retainResult is an optional boolean for submit/dynamic routes, defaults to true, and is prohibited on query routes. Set it to false only when every successful submission completes immediately. An immediate terminal result does not persist task.data; native queries, Responses/Video retrieval, and artifact listing/content subsequently cannot find the task. The task record remains for billing and logs. The submit presenter still receives the full in-memory data, and completion usage hooks run before that data is discarded.

If a route declaring false returns an asynchronous task, the host retains the result and logs a warning. Responses and Video always retain results. Image returns immediate terminal results inline without retaining result data; results completed by in-request polling retain the poller's snapshot. When a discarded result is referenced, originTasks[].data is null. Older hosts reject the retainResult field.

For openai_image and native routes with retainResult: false, the submit reply, each SSE event and immediate terminal taskData may reach MAX_FILE_DOWNLOAD_MB (64 MiB by default). Retained submit data and accumulated plugin state each have a 1 MiB limit.

Host Protocols

meta.protocols declares protocol paths uniformly managed by the host and should not duplicate these paths in meta.routes:

ProtocolHost PathPlugin Export
openai_videoPOST /v1/videos, GET /v1/videos/{id}, GET / HEAD /v1/videos/{id}/contentprotocols.openai_video.decodeRequest and render
openai_responsesPOST /v1/responses, GET /v1/responses/{id}decodeRequest, and pattern-matching render hooks
openai_imagePOST /v1/images/generations, POST /v1/images/editsprotocols.openai_image.decodeRequest and render

Responses must explicitly declare supports as an object: stream requires renderEvents, sync or background requires renderFinal. Missing required hooks, or exporting hooks not used by any declared pattern, will result in rejection.

Decoders may execute multiple times after candidate filtering and channel selection, and should remain deterministic. Multiple plugins can share models under the same protocol; the actual plugin is determined by the selected channel.

Video render must return a JSON object; the host overrides standard ID, model, status, and time fields, and preserves compliant vendor extensions. Successful results of Responses reference artifacts via ctx.artifacts[key].url injected by the host.

OpenAI Image protocol

Declare "openai_image" or { name: "openai_image", models: [...] } without supports. Like openai_video, it defines no request modes; both allow string claims or objects with model restrictions. Generation accepts JSON; editing accepts JSON or multipart. The host pins ctx.model and provides ctx.operation: "generate" | "edit".

Export decodeRequest and render. A synchronous upstream returns a terminal immediate from parseSubmitResponse; an asynchronous upstream returns a task ID, and the host waits within the client request using the ordinary query hooks. TASK_PLUGIN_PROTOCOL_TIMEOUT_SECONDS defaults to 600 seconds; a timeout returns 504 task_timeout. After a timeout or client disconnect, the submitted task still completes and settles through background polling. Terminal task failure returns 400 with the failure reason.

On success, render(ctx, task) returns an object with a data array of { url } or { b64_json } entries, optionally including revised_prompt. The host adds created when absent. For response_format: "b64_json", it downloads image URLs and adds Base64 while preserving the URLs; failed downloads produce a warning and leave the URLs. This hook receives no ctx.artifacts; image URLs come from the upstream result.

For openai_image, the selected channel applies parameter overrides to JSON or multipart text fields before the final decodeRequest. The hook validates this request. Uploaded files keep their references. Each retry starts from the original request. Use channel model mapping to change the upstream model. render and the host use the effective response_format of the final attempt.

Usage Hooks

Optional exports extractUsage, extractUsageOnSubmit, and extractUsageOnComplete extract usage from requests, submission results, or completion results, respectively. Return usage facts, never prices or quotas. Facts declared by the selected schema must satisfy its validation rules.

usageProfiles supplies complete schemas and examples for its models, replacing defaults without merging or inheritance. Runtime selection first matches the final upstream model. If that name has no profile (for example, it is mapped to a vendor endpoint ID), it falls back to the client-facing model, then to the plugin defaults. Saved prices are not automatically migrated. See Usage and Billing.

When removing a field from a model's profile, keep reporting its released key with a value that preserves existing charges: 0, false, or the first declared enum value. Saved single-plugin expressions can therefore continue to use those facts. Editing an expression must follow the current schema; shared models still require provider-specific field compatibility.

Numeric field descriptions name the billing subject and unit price, such as Image generation unit price / 图片生成单价; the actual field value remains a usage quantity. Put units in unit, count display words in unitLabel, and enum display names in enumLabels. Action, boolean, and enum descriptions name the action, the state represented by true, and the condition, respectively. Keep translations equivalent, without numeric prices, protocol details, or trailing punctuation.

Artifacts and Content Requests

Artifact hooks must be exported in pairs:

  • listArtifacts(task): Projects a stable list of { key, type, mimeType? } from persisted data, without returning a second persisted record or temporary download URL.
  • buildContentRequest(ctx): Constructs the read descriptor for this request based on the selected artifact key, data, production version, upstream task ID, channel information, and secure Range/conditional request headers.

Content requests with channel credentials can only access channel hosts or allowedHosts. Public dynamic CDNs can use credentialless: true; in this case, only GET/HEAD is allowed, no plugin headers or body can be attached, and the host will check the initial address and redirects.

When a credentialed buildContentRequest URL has the same scheme, hostname and effective port as the task channel’s base URL, the gateway uses that channel’s HTTP client, including its private upstream settings. Redirects must stay on that origin. Other origins, including allowedHosts, and credentialless requests use the global fetch restrictions.

Host artifact links use TaskPublicAddress, falling back to ServerAddress by default. Multi-node setups require a shared valid CRYPTO_SECRET; rotating it will invalidate issued addresses.

Immediate Completion, SSE, and Host Capabilities

parseSubmitResponse can return an immediate final state result, allowing the host to complete persistence and settlement during the submission phase; these tasks will not continue polling.

When upstream submission uses SSE, declare submitResponseTypes: ["json", "sse"] and select responseType: "sse" in the descriptor:

ModeRequired Declarations and ExportsData Flow
SnapshotparseSubmitEventEach event returns { state, done }, and the complete state after completion serves as the body of parseSubmitResponse
IncrementalrequiredCapabilities: ["submit-sse-delta@1"], parseSubmitEventDeltaReturns { changes, state, done }, the host applies set / append / appendText, and the body is formed upon completion

The host passes returned SSE state to the next event as previousState. Mutating previousState without returning the new state does not preserve the change. Non-plain JSON state, such as a typed array, is normalized through JSON encoding. Every event's state is checked against its actual encoded size, including an intermediate state later replaced by a smaller one.

Cancellation callbacks finish before a runtime returns to the pool, and the engine releases references to the completed call's arguments. Values retained in module variables still keep their data alive. No JavaScript execution slot is held while waiting for upstream events.

SSE mode does not directly pass upstream events to the client. The plugin interprets event semantics and termination conditions, while the host manages connections, frame parsing, size limits, and timeouts; read failures after successfully accepting upstream SSE will not automatically retry submission, to avoid creating duplicate billing tasks.

json-clone@1 provides a synchronous utils.json.clone(value) for creating mutable, independent JSON snapshots. Other utilities include time, UUID, Base64, HMAC, JWT, and Volc signature tools; see type declarations for full signatures. requiredCapabilities must declare the exact version; unknown or unsupported capabilities will be rejected at load time.

utils.json.clone accepts up to 4 MiB of encoded JSON, 32 levels below the root and 32,768 nodes. Where a hook permits utils.fetch, each call to the hook allows up to four fetches, 15 seconds per fetch and 30 seconds in total. Response bodies may use up to 4 MiB each and 8 MiB in total. Bytes read from failed or interrupted responses count toward the total.

Management and Diagnostic Interfaces

The Root management interface is located at /api/plugin/task, including upload, version activation, status switching, deletion, marketplace source, dry run, and /runtime/status. These management operations are not part of the same permission system as /v1/tasks accessed with an API key.

The runtime is published atomically as a complete generation. Requests consistently use one generation, while background polling may use updated plugins. Multi-node troubleshooting should compare database override revisions, not directly compare the auto-incrementing generation numbers of each node.

For debugging steps, see Development Guide; for release checks, see Publishing Specification.

How is this guide?

Last updated on