Crynux Bridge

Deploy Crynux Bridge for Applications

Crynux Bridge is middleware that connects traditional applications to the Crynux Network. It simplifies using the Crynux Network for applications by handling all complex interactions with the Crynux Network. The application only needs to interact with the Crynux Bridge by sending task parameters and waiting for the result images or texts.

More specifically, the Crynux Bridge:

  1. Manages the application wallet, signs the underlying transactions and API requests.

  2. Interacts with the blockchain and Relay to execute the entire task workflow.

  3. Provides simpler APIs to the application to execute tasks using only the task parameters(no blockchain transactions or signatures).

This document provides a step-by-step guide to deploy the Crynux Bridge and connect it to your application.

Get the Docker Compose Files

The Docker Compose files are located in the build folder of the Crynux Bridge project:

Download the folder to the deployment server, or clone the whole project:

$ git clone https://github.com/crynux-ai/crynux-bridge.git
$ cd build

Application Wallet Configuration

The application wallet's private key will be loaded from a file in the build folder and stored as Docker secrets. For security, this file can be deleted once the container is created. Ensure to back up the private key, as it will be required again if the container needs to be recreated.

Create a file named privkey.txt and paste the private key into the file. The private key should be a hex string prefixed with 0x.

# Inside the build folder

$ cat "0xabcd...23cd" >> privkey.txt

Database Configuration

Crynux Bridge relies on a database to store data. A MySQL instance is configured in the Docker Compose file by default.

If the default configuration meets your needs, no further action is required. If you need to use another database instance, remove the service section of MySQL in the docker-compose.yml file, and modify config/config.yml to use another database instance:

# config/config.yml

db:
  driver: "mysql"
  connection: "crynux_bridge:crynuxbridgepass@(mysql:3306)/crynux_bridge?parseTime=true"
  log:
    level: "info"
    output: "/app/data/logs/crynux_bridge_db.log"
    max_file_size: 100
    max_days: 30
    max_file_num: 5

Start the Docker Container

In the build folder, run the following command to start the containers:

# Inside the build folder

$ docker compose up -d

Use the Crynux Bridge APIs

The application can utilize the APIs of the Crynux Bridge to send tasks and receive results. The description of the APIs can be accessed as the OpenAPI Specification on the started Crynux Bridge instance. Assume the IP address of the instance is 192.168.1.2, the JSON schema of the specification can be accessed at:

http://192.168.1.2/openapi.json

And a human readable documentation can be accessed at:

http://192.168.1.2/static/api_docs.html

As an example, the URLs of the Crynux Bridge used by the showcase applications online are:

API List

Get the balance of the application wallet

GET/v1/application/wallet/balance
Response

OK

Body
dataWalletBalance (object)
messagestring

The response message. Will be 'success' or a detailed error type

Request
const response = await fetch('/v1/application/wallet/balance', {
    method: 'GET',
    headers: {},
});
const data = await response.json();
Response
{
  "data": {
    "address": "text"
  },
  "message": "text"
}

Create an inference task

POST/v1/inference_tasks
Body
client_id*string

Client id

task_args*string

Task args

task_type*nullable integer (int32)

Task type. 0 - SD task, 1 - LLM task

vram_limitnullable integer (int64)

Task minimal vram requirement

Response

OK

Body
dataInferenceTask (object)
messagestring

The response message. Will be 'success' or a detailed error type

Request
const response = await fetch('/v1/inference_tasks', {
    method: 'POST',
    headers: {
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      "client_id": "text",
      "task_args": "text"
    }),
});
const data = await response.json();
Response
{
  "data": {
    "abort_reason": "text",
    "created_at": "2024-07-22T20:38:20.126Z",
    "deleted_at": {
      "Time": "2024-07-22T20:38:20.126Z",
      "Valid": false
    },
    "result_node": "text",
    "task_args": "text",
    "tx_hash": "text",
    "updated_at": "2024-07-22T20:38:20.126Z"
  },
  "message": "text"
}

Get task details by task id

GET/v1/inference_tasks/{client_id}/{task_id}
Path parameters
client_id*string

Client id

task_id*integer (int32)

Task id

Response

OK

Body
dataInferenceTask (object)
messagestring

The response message. Will be 'success' or a detailed error type

Request
const response = await fetch('/v1/inference_tasks/{client_id}/{task_id}', {
    method: 'GET',
    headers: {},
});
const data = await response.json();
Response
{
  "data": {
    "abort_reason": "text",
    "created_at": "2024-07-22T20:38:20.126Z",
    "deleted_at": {
      "Time": "2024-07-22T20:38:20.126Z",
      "Valid": false
    },
    "result_node": "text",
    "task_args": "text",
    "tx_hash": "text",
    "updated_at": "2024-07-22T20:38:20.126Z"
  },
  "message": "text"
}

Get task details by task id

GET/v1/inference_tasks/{client_id}/{task_id}/images/{image_num}
Path parameters
client_id*string

Client id

image_num*string

Image number

task_id*integer (int32)

Task id

Response

OK

Request
const response = await fetch('/v1/inference_tasks/{client_id}/{task_id}/images/{image_num}', {
    method: 'GET',
    headers: {},
});
const data = await response.json();

Get the list of the base models

GET/v1/models/base
Response

OK

Body
dataarray of BaseModel (object)
messagestring

The response message. Will be 'success' or a detailed error type

Request
const response = await fetch('/v1/models/base', {
    method: 'GET',
    headers: {},
});
const data = await response.json();
Response
{
  "data": [
    {
      "created_at": "2024-07-22T20:38:20.126Z",
      "deleted_at": {
        "Time": "2024-07-22T20:38:20.126Z",
        "Valid": false
      },
      "description": "text",
      "key": "text",
      "link": "text",
      "name": "text",
      "type": "text",
      "updated_at": "2024-07-22T20:38:20.126Z"
    }
  ],
  "message": "text"
}

Get the list of the lora models

GET/v1/models/lora
Query parameters
Response

OK

Body
dataarray of LoraModel (object)
messagestring

The response message. Will be 'success' or a detailed error type

Request
const response = await fetch('/v1/models/lora', {
    method: 'GET',
    headers: {},
});
const data = await response.json();
Response
{
  "data": [
    {
      "created_at": "2024-07-22T20:38:20.126Z",
      "deleted_at": {
        "Time": "2024-07-22T20:38:20.126Z",
        "Valid": false
      },
      "description": "text",
      "display_link": "text",
      "download_link": "text",
      "name": "text",
      "type": "text",
      "updated_at": "2024-07-22T20:38:20.126Z"
    }
  ],
  "message": "text"
}

GET/v1/network/nodes
Response

OK

Body
dataNodeStats (object)
messagestring

The response message. Will be 'success' or a detailed error type

Request
const response = await fetch('/v1/network/nodes', {
    method: 'GET',
    headers: {},
});
const data = await response.json();
Response
{
  "data": {},
  "message": "text"
}

Last updated