Sharp Aion2 Lua SDK
API reference

httpLua table

Make asynchronous web requests and save private script profiles.

The http table queues web requests and private profile operations. For http.get and http.post, URLs are at most 2048 bytes and responses at most 64 KiB. Requests time out after 10 seconds. A loaded module receives the result in on_http(requestId, status, body, error).

http.get(url)

Parameters: url is an HTTP or HTTPS URL. Returns: A numeric request ID when queued, or nil, error. Queueing does not mean the request succeeded.

function on_start()
    local requestId, err = http.get("https://example.com/")
    if not requestId then log.warn(err) end
end

http.post(url, body)

Parameters: url follows the same URL rule. body is a string of at most 64 KiB. Returns: A numeric request ID when queued, or nil, error.

function on_start()
    local requestId, err = http.post("https://example.com/api", "hello")
    if not requestId then log.warn(err) end
end

http.post_json(url, body [,bearerToken])

Queue an asynchronous JSON POST with optional Authorization: Bearer credentials. This optional binding requires an updated loaded Sharp client; SDK 1.7.4 advertises it without changing minimum SDK API version 6. Check type(http.post_json) == "function" before using it. Older http.post cannot send a bearer token.

URLs must use HTTPS, or HTTP on 127.0.0.1, localhost or [::1]. URLs cannot contain user information, query strings, fragments, whitespace or backslashes. Bearer tokens allow up to 512 printable ASCII bytes without spaces or controls. Bodies and responses are limited to 64 KiB; network operations time out after 30 seconds. Redirects are disabled. The method sets Content-Type: application/json; the script supplies JSON text. Results use the usual on_http callback.

Pass credentials only at runtime. Do not place keys in Lua source, saved profiles, logs, package uploads or prompts. Queueing returns a numeric request ID or nil, error; a failed or uncertain request must not be replayed.

local pending
local function requestJson(endpoint, encodedBody, sessionKey)
    if type(http.post_json) ~= "function" then
        return nil, "Update Sharp for authenticated JSON requests"
    end
    local id, err = http.post_json(endpoint, encodedBody, sessionKey)
    if id then pending = id end
    return id, err
end

function on_http(requestId, status, body, err)
    if requestId ~= pending then return end
    pending = nil
    if err ~= "" or status ~= 200 then
        log.warn("JSON request failed; no retry")
        return
    end
    -- Decode and validate body as data before using it.
end

The Auto Chat guide uses this binding with OpenAI-compatible text providers.

Private online profiles

Profiles are private and linked to this computer, using the same identity as My Configs. They do not require account sign-in. Each scope has its own named profiles, so a gathering script can keep its settings separate from other scripts. The script does not receive the machine identifier.

The three profile methods require a loaded client that exposes them. SDK 1.7.1 keeps minimum SDK API version 6; the profile methods are optional client capabilities. Downloading a Lua library alone cannot add them to an older client. Check all three methods with type(http.config_list) == "function", type(http.config_save) == "function", and type(http.config_load) == "function" before showing profile controls.

These methods are available to loaded modules. They return a numeric request ID when queued, or nil, error. Keep that ID and handle the result in on_http. A queued request does not mean a profile was saved or loaded. Reloading or unloading the module discards callbacks belonging to its previous Lua instance.

ArgumentLimit
scope1–24 lowercase letters, digits, or underscores.
name1–32 UTF-8 bytes, without control characters. Leading and trailing spaces are trimmed. The complete stored name, including its scope prefix, must fit 50 bytes.
contentAn opaque UTF-8 string of at most 32 KiB, without NUL characters. Tabs and newlines are allowed. The script chooses and validates its own format.
idA 24-character hexadecimal profile ID returned by the list.

Use the same scope for listing, saving, and loading. Loading returns profile content; it does not run it or apply settings automatically. Validate the content before replacing your script's current settings.

At most eight profile requests can be outstanding across loaded scripts. List responses are bounded to 64 KiB; save and download operations allow up to 256 KiB on the wire to preserve escaped text within the 32 KiB content limit. Completed callbacks contain only the list, save result, or decoded content. Profile failures return generic errors without exposing the computer identity or service response details.

The Gathering guide shows these operations in the Configs tab of Abyss Gather & Instances.

http.config_list(scope)

Queue a list of profiles in the scope. On success, the callback body begins with sharp-lua-config-list-v1\n, followed by one line per profile:

id<TAB>name<TAB>updatedAt

updatedAt is a Unix timestamp in milliseconds. An empty list contains only the header. The list supports at most 100 profiles per scope; a larger result returns an error. Split the rows on tabs and validate each ID before passing it to http.config_load.

local pendingList
local profiles = {}

function on_start()
    local requestId, err = http.config_list("gathering")
    if not requestId then
        log.warn(err)
        return
    end
    pendingList = requestId
end

function on_http(requestId, status, body, err)
    if requestId ~= pendingList then
        return
    end
    pendingList = nil
    if err ~= "" or status ~= 200 then
        log.warn(err ~= "" and err or "Could not list profiles")
        return
    end
    local header = "sharp-lua-config-list-v1\n"
    if body:sub(1, #header) ~= header then
        return
    end
    profiles = {}
    for row in body:sub(#header + 1):gmatch("[^\n]+") do
        local id, name, updatedAt = row:match("^([0-9a-fA-F]+)\t([^\t]+)\t(%d+)$")
        if id and #id == 24 then
            profiles[#profiles + 1] = {
                id = id, name = name, updatedAt = tonumber(updatedAt)
            }
        end
    end
end

http.config_save(scope, name, content)

Queue a save. Saving the same name in the same scope updates that profile. A successful callback has status 200, an empty error, and body saved or updated.

If the error says the save outcome is unknown, refresh the list before retrying. The profile may have been saved even though its reply was lost.

local pendingSave

function on_start()
    local content = "schema=1\nsearch_radius=100\n"
    local requestId, err = http.config_save("gathering", "River route", content)
    if not requestId then
        log.warn(err)
        return
    end
    pendingSave = requestId
end

function on_http(requestId, status, body, err)
    if requestId ~= pendingSave then
        return
    end
    pendingSave = nil
    if status == 200 and err == "" and (body == "saved" or body == "updated") then
        log.info("Online profile " .. body)
    else
        log.warn(err ~= "" and err or "Could not save profile")
    end
end

http.config_load(scope, id)

Queue a download of a profile in the scope. A successful callback has status 200, an empty error, and the original opaque content as its body. A profile from a different scope is rejected.

local pendingLoad
local profileContent

function on_start()
    -- Replace this example ID with an ID returned by config_list.
    local requestId, err = http.config_load("gathering", "0123456789abcdef01234567")
    if not requestId then
        log.warn(err)
        return
    end
    pendingLoad = requestId
end

function on_http(requestId, status, body, err)
    if requestId ~= pendingLoad then
        return
    end
    pendingLoad = nil
    if status == 200 and err == "" then
        profileContent = body
        -- Decode and validate profileContent before applying it.
    else
        log.warn(err ~= "" and err or "Could not load profile")
    end
end

Response callback

on_http(requestId, status, body, error) receives the matching request ID, response status, response text, and error text.

function on_http(requestId, status, body, error)
    if error ~= "" then
        log.warn(error)
    else
        log.info(string.format("Request %d returned %d", requestId, status))
    end
end

On this page