API Conventions
This page describes common conventions that can be relied upon when calling the NexusFlow HTTP API directly, and differences that cannot be inferred across interfaces. Before starting to write the client, first confirm the path, method, permissions, request fields and return examples of the target interface; this page cannot replace the interface description of each resource.
Splice Interface Path from Platform Root Address
base_url should fill in the root address of the platform actually accessed by the user, for example:
https://nexusflow.example.com
The current main HTTP interface is mounted under /api/, for example:
GET /api/meta/
GET /api/models/<model_uuid>/
POST /api/jobs/
The complete address consists of "platform root address + interface path":
https://nexusflow.example.com/api/meta/
Do not repeatedly add /api/ to the root address, and do not add unified version prefixes such as /v1 that are not provided by yourself. The platform may also provide authorization pages, real-time connections or static resource paths that are not under /api/. These paths should be processed separately according to the corresponding documents.
Request Header and Request Body
It is recommended to declare when reading JSON:
Accept: application/json
Authorization: Bearer <access_token>
When submitting JSON add:
Content-Type: application/json
The JSON request body must be valid UTF-8 JSON. Field names, required fields, null value meanings, and nesting structures are determined by the specific interface; do not send Python's None , single-quote dictionaries, or annotated text directly as JSON.
Not all requests use JSON: interfaces that upload or import packages may ask for multipart/form-data , and export interfaces may return files directly. When using curl -F, do not manually set the Content-Type of multipart, let curl automatically supplement the boundary; when downloading, save the file according to the corresponding Content-Type and Content-Disposition.
For access token acquisition and refresh, see Authentication and Token Refresh.
Common Successful Responses
Most business interfaces use the following encapsulation:
{
"message": "获取数据成功",
"code": 0,
"data": {}
}
The common meanings of the three fields are as follows:
| Field | Meaning |
|---|---|
message | Result descriptions for human reading should not be used as stable program branch conditions |
code | Common business result codes; currently commonly used are 0 for success and 1 for failure. |
data | Business data, which may be an object, array, scalar or null |
Create, update and read interfaces often place resources in data; some successful operations only have message and code, but not data. The client should first determine whether the field exists and then parse it according to the actual type.
Not All Interfaces Use the Same Response
message/code/data cannot be applied to the following situations:
- Login and token refresh use the authentication component’s own token structure;
- Some framework-level authentication, permission and parameter errors may return
detail, or directly return field error objects; - Original data interfaces such as calculation example JSON will directly return business JSON without including a layer of
data; - File export returns binary content;
204 No ContentThere is no parsable response body;- Live connections use a separate messaging protocol, not a plain JSON response.
Therefore, HTTP clients should read the status code and Content-Type before deciding whether to parse the JSON, save the file, or handle it as a null response. Do not call response.json() unconditionally after all requests.
Determine HTTP Status and Business Fields at the Same Time
The HTTP status code describes the transmission and interface processing results, and code in the response body describes the business results when universal encapsulation is used. The two are related, but not the same value.
There are compatibility differences in the current interface: some business errors will return HTTP 4xx or 5xx; there are also a few interfaces that still use HTTP 200 when returning code: 1. In turn, a 4xx response produced directly by the framework may not have code . The reliable judgment sequence is:
- Save HTTP status code and response
Content-Type; - Non-2xx will be handled as failure first, and then the available error text will be parsed;
- 2xx and the response is a universal JSON package, continue to check
code; -
- Original JSON and file responses are processed according to the interface contract, and
codeis not required.
- Original JSON and file responses are processed according to the interface contract, and
Common states are as follows:
| HTTP Status | Common Meanings in the Current Interface |
|---|---|
200 OK | Read, update, or business operation complete; still needs to check for code in the generic package |
201 Created | Partially created interface successful; not all POST return 201 |
204 No Content | The operation is successful but there is no response body, which is common when the interface is partially deleted. |
400 Bad Request | The JSON, field, parameter, or current operating condition is invalid |
401 Unauthorized | No valid authentication information was provided, or the access token has expired |
403 Forbidden | The identity is valid but does not have the target resource or operation permissions |
404 Not Found | The path or resource does not exist; some interfaces also use it to hide inaccessible resources. |
409 Conflict | The request conflicts with the current resource status or relationship |
410 Gone | The data associated with the record has been cleared or expired and cannot be retried with a normal 404. |
500 Internal Server Error | An unexpected exception occurred in service processing |
503 Service Unavailable / 504 Gateway Timeout | The dependent service is unavailable or the processing times out; the final status of the write request may still require query confirmation |
Don’t just judge the error type based on the Chinese keywords in message, and don’t treat the business code as an HTTP status code.
Correct Use of Resource Identifiers
The platform does not have one ID type that works for all resources:
| Resource Example | Common Logo Types | Usage |
|---|---|---|
| Model, model snapshot, job, running snapshot | UUID | Usually a string in JSON, use the standard hyphenated form in the path |
| User, organization, membership, host, and action records | integer ID | JSON is usually an integer, and the path parameter is passed in according to the interface requirements. |
| workspace, component definition | Stable string Key | Case sensitive, do not substitute display name |
| Job underlying running ID | string | It is not guaranteed to be a UUID and cannot replace the job UUID. |
Do not convert integer IDs and UUIDs to and from each other, and do not assume that they belong to the same resource just because the field names are both called id. When saving the association, record the resource type and the parent resource to which it belongs; for example, the sheet or component ID inside the model must also be used together with the model UUID.
Preserve Trailing Slash per Document
Most REST paths end with /. The service currently has common slash handling enabled. Read requests missing a trailing slash may receive redirects, but redirects cannot be relied upon to fix write requests: the client may change methods, lose the request body, or be rejected by the proxy.
There are also a few paths that are implemented explicitly without a trailing slash. The full path given in the specific interface document should be copied and not added or deleted uniformly on the client. When debugging 301 , 302 , 307 or 308 , first compare the request path to the document instead of directly enabling auto-follow redirects for all requests.
Paging, Filtering and Sorting Confirmed by Interface
The platform does not have a global paginator, nor does it have a set of query parameters that are supported by all lists. The main differences currently include:
| List Type | Current Common Forms |
|---|---|
| Model, user, organization and job management lists | page=1 and page_size=20 are commonly used. Most of them set the upper limit of each page to 100 and return data.results and data.pagination. |
| Operation and maintenance resource list | page_size=10 is commonly used, the upper limit is usually 100, and the paging structure is similar to the business list |
| Mission log | The default is 200 per page, the upper limit is 500, and supports log level and keyword filtering. |
| Workspace, organization members, running snapshots, etc. lists | It is possible to directly return an array or object in data and does not provide a unified paging structure. |
A typical paging object is as follows, but only interfaces that explicitly declare paging can rely on it:
{
"results": [],
"pagination": {
"current_page": 1,
"page_size": 20,
"total_pages": 1,
"total_count": 0,
"has_next": false,
"has_previous": false
}
}
Also note:
- Parameters such as
search,fields,count_only,query_typeonly exist on some interfaces; - Some
orderingaccept multiple fields separated by commas, some only accept one whitelist field, and some do not support sorting at all; - Some interfaces will ignore invalid sort fields, or restore invalid page numbers and number of items per page to their default values instead of returning 400;
- Some lists use fixed caps to control costs, but do not return pagination information;
- The default sorting is determined by the resource and cannot be assumed to be all in reverse order of creation time.
The caller should declare the allowed filtering and sorting parameters separately for each list and advance the page number from pagination in the actual response. Do not replace has_next with "Return quantity less than page_size " unless the interface has no paging metadata and the documentation explicitly allows this.
The Time Field Does Not Have a Unique Format Across All Platforms
The current common date and time strings for major business resources are:
YYYY-MM-DD HH:mm:ss
This set of interfaces works according to the platform's local time zone Asia/Shanghai, and the string itself does not have a UTC offset. Some specialized interfaces or operation and maintenance resources may use the ISO 8601 form, and the business time in the original snapshot and results may also be determined by the component that generated the data.
Clients should not use only one fixed slicing method to parse all time fields. When reading, process the format according to the field document; when submitting the time, use the format specified by the target interface example. Do not delete the time zone offset without authorization or treat the local time as UTC. When it is necessary to store across time zones, the original string, interface semantics and parsed time with time zones are saved at the same time.
Understand the Actual Boundaries of PUT, PATCH and DELETE
HTTP methods express operation intentions, but the current interface does not force all resources to have exactly the same update semantics:
PATCHis commonly used to update some fields of users, organizations and members;- Model update uses
PUT, and the current implementation allows only the fields to be modified to be submitted; PUTof resources such as workspace definition may be written as complete JSON content, and missing fields may cause content loss;DELETEmay be logical deletion, physical deletion, cleaning of associated files, or triggering an asynchronous operation. Please read the specific interface description first.
There is no unified response form for successful deletion: some interfaces return HTTP 200 and general JSON, some return 204 without text, and some return 200 and give the deleted resource ID in data. The caller should treat 204 as success and skip JSON parsing.
Before updating or deleting, read the target resource and check the ID, type, update time, and permissions scope. For the fully defined class PUT, keep the current content and fallback copy, do not just send a local field to test the interface behavior.
Check Idempotence Before Retrying
The platform currently does not have a unified Idempotency-Key contract. Adding a request header with the same name yourself will not automatically prevent duplicate creation or duplicate operations.
Retry strategies can be formulated according to the following boundaries:
- Read
GETcan usually retry with exponential backoff and random jitter after a network outage, 502, 503 or 504; - Update requests that explicitly cover the same value of the same resource may have idempotent effects, but concurrent writes and interface side effects must still be considered;
- Requests such as model creation, job creation, import, installation, publishing and service operations cannot be sent directly and repeatedly after timeout, otherwise copies may be created or executed repeatedly;
- Calling
DELETEagain may return 404, business errors or different results, and it cannot be assumed that all deletions are naturally repeatable; - When receiving a 409 or 410, you should handle resource status conflicts or data expiration first, and do not try again as a transient network error.
When a write request encounters a connection interruption or gateway timeout, first confirm whether the request has taken effect through the resource list, details or operation records. The write request will only be reissued if it can be proven that it was not executed the previous time, or if the specific interface provides clear protection against repeated submissions. If the response provides Retry-After, wait as required; without this response header, do not infer a fixed retry period.
Execute the First Curl Request Using Environment Variables
The read-only request below confirms the root address, certificate, token, and /api/ path. Environment variables should be injected by the terminal session or key system, not written to the repository:
export NEXUSFLOW_BASE_URL="https://nexusflow.example.com"
export NEXUSFLOW_ACCESS_TOKEN="<由安全方式注入>"
curl --silent --show-error --fail-with-body \
--header "Accept: application/json" \
--header "Authorization: Bearer ${NEXUSFLOW_ACCESS_TOKEN}" \
"${NEXUSFLOW_BASE_URL%/}/api/meta/?scope=access"
You can use the same variables when submitting JSON and have the request body come from the censored file:
export NEXUSFLOW_API_PATH="/api/models/validate/"
curl --silent --show-error --fail-with-body \
--request POST \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer ${NEXUSFLOW_ACCESS_TOKEN}" \
--data-binary @validate-request.json \
"${NEXUSFLOW_BASE_URL%/}${NEXUSFLOW_API_PATH}"
validate-request.json must be prepared according to the model verification interface. --fail-with-body causes HTTP 4xx/5xx to return a non-zero exit code and preserve the error text, but it does not recognize code: 1 in HTTP 200; the script still needs to parse the generic response.
Use $env:NEXUSFLOW_BASE_URL and $env:NEXUSFLOW_ACCESS_TOKEN when setting environment variables in Windows PowerShell, and the splicing method of the request URL is adjusted according to PowerShell syntax. Don't write tokens directly in commands that save history.
Safety Precautions
- Use HTTPS in the production environment and verify the certificate. Do not use
curl -kor turn off client certificate verification to cover up configuration problems; - Do not save access tokens, refresh tokens, and passwords in URL query parameters, logs, exception traces, screenshots, or repositories;
- Avoid outputting the complete
Authorizationrequest header during debugging; desensitize it before sharingcurl -vor capturing packet content; - Only send tokens to trusted platform root addresses, and must not continue to carry authentication headers when redirecting to other hosts;
- Set the caller's own size, type, and source limits on uploaded files, model snapshots, and batch parameters;
- Do not display the exception details returned by the server to irrelevant users as they are, and remove credentials, personal information and business data when retaining information required for troubleshooting;
- Use a least privileged account and keep development, test, and production credentials separate.
Troubleshoot Failed Requests in Order
- Check Full URL: Whether the root address is correct, whether
/api/is repeated, and whether the path and trailing slash are consistent with the interface document. - Check HTTP Layer: Record status code, redirection history and
Content-Type; first distinguish between JSON, empty response, file and proxy error pages. - Check Response Structure: See
code,message, anddataat the same time for general packages; seedetail, field errors, or original text for non-universal responses. - Check Authentication and Permissions: Confirm that the token has not expired and the current account does have the right to access the target workspace and resources; see Authentication and Token Refresh.
- Check Identifier: Confirm that UUID, integer ID, string Key and job running ID are not mixed, and the path parameters belong to the correct resources.
- Check Query and JSON: Only send filters, sorting, and fields supported by this interface; confirm the JSON type, required fields, and time format.
- Confirm Server Status: After the write request times out, check the resource details, list or operation record first, and do not repeat the execution immediately.
- Minimize Recurrence: Keep the method, desensitized URL, status code, response header and response body, and use the minimum read-only request to verify the same authentication link.
If the browser page is normal but the script fails, give priority to comparing the root address, path, authentication header and request body of the actual requests between the two, rather than just comparing the parameter values displayed on the page.