API#

The API screen serves as a reference for available API methods in Swagger format.

There are now three tabs available on the API screen:

  1. Swagger
    This subsection opens the interactive API documentation. Users can view available requests, their parameters, response structure, and use Swagger as a reference for checking integrations.

Documentation is also available at the link:

Sherpa AI Server API - Swagger UIaiserver.sherparpa.ru
  1. ReDoc
    This subsection opens an alternative view of the API documentation.

ReDoc is convenient for reading: it is easier to browse method descriptions, data schemas, and required fields for requests.

  1. Token
    The Token subsection is intended for managing access tokens to the API in Sherpa AI Server.

    On the API tokens screen, a table is displayed with a list of created API tokens.

For each token in the list, the following are shown:

ColumnDescription
API Token NameName for the token.
RolesRole assigned to the token.
ExpirationExpiration date of the token or "Never expires".
CreatedDate and time the token was created.

In each row, the following actions are available for the token on the right:

  • update / reissue the token;
  • edit the token;
  • delete the token.

Regenerating a token immediately invalidates its previous secret. The new secret is shown only once. It is important to copy it and update every integration that uses this token. If the new value was not saved, the token needs to be regenerated again.

Above the table are buttons:

  • "Create" — opens a popup window to create a new API token.

In the window, you need to specify the API token name and select roles from the dropdown list. Both fields are mandatory.

You can also set the token's expiration. If you check the "Never expires" checkbox, the token will be created without an expiration date. If the checkbox is not selected, the "Expiration" field specifies the date and time until which the token will be active. A calendar icon is available for selecting the date.

At the bottom of the window, there are two buttons: "Cancel" closes the window without saving, while "Create" creates a new API token. The create button becomes available after filling in the mandatory fields.

After creation, store the displayed token value securely and use it only in integrations with the roles assigned to it.

  • Refresh — reloads the list of tokens on the API tokens screen.

Swagger requests without body parameters#

Requests require a valid API token whose role permits the selected action, or an authenticated session. Requests operate within the current account. The account_guid field is unnecessary: the server determines the account from the token or session.

Before executing a request, its conditions must be checked. Asynchronous execution requires the waiting status. Deletion must be checked only on objects created for this check in a separate Account. An Object Folder with child folders cannot be deleted.

Requests can be executed in Swagger as follows:

  1. It is necessary to open the "Swagger" tab. For API-token authentication, the "Authorize" button must be clicked and the token value entered. Session authentication requires signing in to Sherpa AI Server.

  2. It is necessary to select a method and click "Try it out". It is necessary to enter the GUIDs of existing objects in the path parameters.

  3. For POST /api/v1/threads/{thread_guid}/runs/{run_guid}/execute_async, an empty JSON object must be left in "Request body":

    {}
    

    This request requires the Content-Type: application/json header.

  4. The following deletion methods have an optional request body. You can send a request without a body or a Content-Type header:

    • DELETE /api/v1/folders/{folder_guid}/files/{file_guid};
    • DELETE /api/v1/folders/{folder_guid};
    • DELETE /api/v1/object_folders/{object_folder_guid}.

    Existing JSON requests, including {}, remain supported. For a JSON body, set the Content-Type: application/json header.

  5. It is necessary to click "Execute" and check the response code.

A successful asynchronous launch returns 200 and the in_progress status. Generation completes later. A successful deletion returns 204 without a body. Test deletion on test objects.

For a 403 response, check authentication and role permissions. For 404, check the GUIDs and whether the objects belong to the current account. The run must have the waiting status. An external-response run is completed through an API client. An object folder containing subfolders cannot be deleted.

For a 422 response, check that authentication credentials are present, any JSON body sent is valid, and the Content-Type header is set correctly.

Chat Completions: context, tools and errorsdocs.sherparpa.ru

Reading system errors#

External monitoring uses GET /api/v1/system_errors. The token needs the read action in the Role field access_audit. Write permissions are not required to read the list. Copy the authorization header format from the token creation dialog and check it against Swagger for the installed version.

The filter filters[level][from]=400 selects error, critical, alert and emergency entries and excludes warnings. Use to for an upper bound and equal for an exact value. Bounds are inclusive. When equal is present, from and to are ignored. The existing filters[level]=400 filter retains exact equality.

Sorting uses one sort[field] and sort[order]=asc|desc. Available fields: id, level, created, updated, channel. Pagination uses pagination[page] starting at 1 and pagination[per_page] from 1 to 100. The default page size is 20 entries.

Replace the server address in the example. At the Authorization: prompt, enter the header value from secure storage, including the authorization scheme. Input is hidden and passed to curl through standard input.

read -r -s -p 'Authorization: ' SHERPA_AUTH
printf '\n'
printf 'Authorization: %s\n' "$SHERPA_AUTH" |
  curl --fail-with-body --get \
    'https://aiserver.example.com/api/v1/system_errors' \
    --header @- \
    --data-urlencode 'filters[level][from]=400' \
    --data-urlencode 'sort[field]=level' \
    --data-urlencode 'sort[order]=desc' \
    --data-urlencode 'pagination[page]=1' \
    --data-urlencode 'pagination[per_page]=20'
unset SHERPA_AUTH

A successful response contains the data array and meta.page, meta.per_page, meta.total. Increase pagination[page] to read the next page. Unknown fields or operators, non-integer bounds and page sizes above 100 are rejected. Correct the parameters before retrying. A paginated list is not a cursor feed with a guarantee of no missed entries.

Connecting OpenCode to a model#

The connection lets OpenCode use a Sherpa AI Server model to answer requests and work with project files.

An administrator must configure an active Model instance and create an API token with a Role that permits "Create" in the "Chat" section. To work with project files in OpenCode, the selected model must support OpenAI-format tool calls. OpenCode performs file operations on the developer's computer.

The example uses the OpenCode 1.19.5 configuration format. Create an opencode.json file in the project folder:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "sherpa": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Sherpa AI Server",
      "options": {
        "baseURL": "https://ai.example.com/api/v1/threads",
        "apiKey": "{env:SHERPA_AISERVER_API_KEY}"
      },
      "models": {
        "ide-coder": {
          "name": "Local coder",
          "limit": {"context": 32768, "output": 4096}
        }
      }
    }
  },
  "model": "sherpa/ide-coder"
}

Replace the following example values:

  • https://ai.example.com with the address of an accessible Sherpa AI Server. Keep the /api/v1/threads suffix. The client appends /chat/completions to this address.
  • ide-coder with the exact name of the configured Model in Sherpa AI Server. Replace it both in the models key and after sherpa/ in the model value. Specify the model manually: this address does not provide a standard OpenAI model list.
  • 32768 and 4096 with the context length and maximum output length in tokens supported by the model.

Before starting OpenCode, set the SHERPA_AISERVER_API_KEY environment variable to the API token value. The token is sent in the Authorization: Bearer header. It does not need to be stored in the project file.

To check the connection, open OpenCode in the project folder and send a short request. The expected result is a response from the selected model. Then allow it to read a test file and create a new file from its contents. The expected result is completed tool calls and a new file containing the required text.

If authorization fails, check the token, its expiry date, and the Role permissions. For a model selection error, check the Model name and instance availability. HTTP 400 with Type 'mixed' is unexpected. indicates an API validation error: the administrator must update Sherpa AI Server to a build containing the fix for OpenAI-compatible parameters.

This endpoint calls the model directly. OpenCode controls the tools and access to project files.

Additional model operations#

Save a model and an active instance, enable the required capability and give the API token permissions for the operation. The model field contains the model card name in the current account. Alternatively, use model_instance_guid for one of its instances. Do not supply both selectors.

Operation Path
Text completion POST /threads/operations/completion
Classification POST /threads/operations/classification
Similarity scoring POST /threads/operations/scoring
Text representations POST /threads/operations/pooling
Text to tokens POST /threads/operations/tokenize
Tokens to text POST /threads/operations/detokenize
Audio translation POST /audio/translations

All paths start with /api/v1. New operations require an explicit model selection. Tokenization and detokenization may use the account Chat default for compatibility with existing requests. An invalid name never falls back to the default. Responses are non-streaming JSON.

Example classification request body:

{
  "model": "Classifier Demo",
  "input": ["First document", "Second document"]
}

Audio translation requires multipart/form-data with the audio in file and an explicit model selection. The maximum file size is 25 MiB. The model protocol determines the target language. Images and videos use image_url and video_url content parts in Chat Completions; no separate video endpoint is needed.

Authenticating Chat requests#

Separate authentication and request format errors help diagnose an API client connection without changing valid JSON.

For POST /api/v1/threads/chat, /api/v1/threads/chat/completions, /api/v1/threads/chat/preflight, and /api/v1/threads/responses, send Authorization: Bearer <API_KEY> or a valid session cookie. Replace <API_KEY> with the API token secret from secure storage.

If the header is missing or does not match the Bearer scheme and no cookie is supplied, the server returns HTTP 403, error.code = access_denied, and repairable = false. Check the environment variable and key transmission in the API client process itself. Changing the request body does not supply missing credentials.

A header alone does not prove that the key is valid. Invalid keys or insufficient permissions are rejected during access checks. A body schema error with authentication data supplied returns HTTP 422, error.code = invalid_arguments, and repairable = true.