# PhoenixGenAI

{% hint style="info" %}
**Good to know:** All GenAI interfaces require token as a request header parameter.
{% endhint %}

## Query a Task

Calling the genAI interface will return a task id, which is the unique identifier for each call. You can use the task id to query the results of the task.

### Polling

<mark style="color:green;">`GET`</mark> `https://www.phoenix.global/sdk/computation/genAI/queryTask`

#### Headers

| Name                                    | Type   | Description                              |
| --------------------------------------- | ------ | ---------------------------------------- |
| token<mark style="color:red;">\*</mark> | string | The token generated in the previous step |

#### Query Parameters

| Name                                       | Type   | Description |
| ------------------------------------------ | ------ | ----------- |
| task\_id<mark style="color:red;">\*</mark> | string | Task id     |

#### Response

{% tabs %}
{% tab title="200: OK Return the URL of the result image" %}

```json
{
    "code": 200,
    "msg": "Success",
    "task_id": "40a5a249-xxxx-xxxx-9ede-0618df6e77e0",
    "result_url": "https://xxxxxx.jpg"
}
```

{% endtab %}
{% endtabs %}

#### CURL and Golang SDK

{% tabs %}
{% tab title="cURL" %}

```bash
curl --location 'https://www.phoenix.global/sdk/computation/genAI/queryTask?task_id=40a5a249-xxxx-xxxx-9ede-0618df6e77e0' \
--header 'token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IjExMUBnbWFpbC5jb20iLCJleHAiOjE2NzgyNzM4Mjh9.7Qy6jh5L1qvVVbOZYR3JrmWdothI2SCF-oGyC2BfZDs'
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/controllers"
)

func main() {
	tokenStr := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IjExMUBnbWFpbC5jb20iLCJleHAiOjE2NzgyNzM4Mjh9.7Qy6jh5L1qvVVbOZYR3JrmWdothI2SCF-oGyC2BfZDs"
	taskID := "40a5a249-xxxx-xxxx-9ede-0618df6e77e0"
	result, err := controllers.QueryTask(taskID, tokenStr)
	...
}
```

{% endtab %}
{% endtabs %}

### Websocket Streaming <a href="#websocket-streaming" id="websocket-streaming"></a>

{% hint style="info" %}
**Good to know:** Generating motion may take a long time. It is recommended to use **WSS** to obtain task results.
{% endhint %}

<mark style="color:red;">`WSS`</mark> `wss://www.phoenix.global/sdk/ws/watch/all`

#### Headers

| Name                                    | Type   | Description                              |
| --------------------------------------- | ------ | ---------------------------------------- |
| token<mark style="color:red;">\*</mark> | string | The token generated in the previous step |

#### Response

{% tabs %}
{% tab title="Returns task ID and the result URL" %}

```json
{
    "task_id": "9ef3a517-xxxx-11ef-8c58-0618df6e77e0",
    "result_url": "https://phoenix.global/ai/files/xxxxxx.jpg"
}
```

{% endtab %}
{% endtabs %}

#### Golang Demo

Demo of using Go language to connect to WSS and read messages.

{% tabs %}
{% tab title="Go" %}

```go
package main

import (
	"fmt"
	"github.com/gorilla/websocket"
)

func main() {
	url := "wss://www.phoenix.global/sdk/ws/watch/all"
	token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IjY2NDk2MjE4NUBxcS5jb20iLCJleHAiOjE2OTk0MzA2Mjh9.l4SpDbOiitrTeJ4Zr89c4ZecXpY9K4DlpZAK9mWrcBw"
	headers := make(map[string][]string)
	headers["Token"] = []string{token}

	dialer := websocket.DefaultDialer
	conn, _, err := dialer.Dial(url, headers)
	if err != nil {
		fmt.Println("failed to connect to websocket: " + err.Error())
		return
	}
	defer conn.Close()
	for {
		_, message, err := conn.ReadMessage()
		if err != nil {
			fmt.Println("failed to read message: " + err.Error())
			return
		}
		fmt.Println(string(message))
	}
}

```

{% endtab %}
{% endtabs %}

## Base GenAI

Generating an image by base mode.

<mark style="color:orange;">`POST`</mark> `https://www.phoenix.global/sdk/computation/genAI/genImg`

#### Headers

| Name                                    | Type   | Description                              |
| --------------------------------------- | ------ | ---------------------------------------- |
| token<mark style="color:red;">\*</mark> | string | The token generated in the previous step |

#### Request Body

| Name                                     | Type   | Description     |
| ---------------------------------------- | ------ | --------------- |
| prompt<mark style="color:red;">\*</mark> | string | Prompt          |
| negative\_prompt                         | string | Negative prompt |

#### Response

{% tabs %}
{% tab title="200 OK: Return the task ID" %}

<pre class="language-json"><code class="lang-json"><strong>{
</strong>  "code": 200,
  "msg": "success",
  "task_id": "40a5a249-xxxx-11ef-9ede-0618df6e77e0",
  "token_cost": 1024,  //The number of tokens consumed by this request
  "token_balance": 137542  //The remaining number of tokens
}
</code></pre>

{% endtab %}
{% endtabs %}

#### CURL and Golang SDK

{% tabs %}
{% tab title="cURL" %}

<pre class="language-bash"><code class="lang-bash">curl --location 'https://www.phoenix.global/sdk/computation/genAI/genImg' \
--header 'Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IjExMUBnbWFpbC5jb20iLCJleHAiOjE2NzgyNzM4Mjh9.7Qy6jh5L1qvVVbOZYR3JrmWdothI2SCF-oGyC2BfZDs' \
--header 'Content-Type: application/json' \
--data '{
<strong>    "prompt": "iron man skiing on steep slope, hd, high quality",
</strong>    "negative_prompt": "ugly,watermark,jpeg artifacts,error,text,username"
}'
</code></pre>

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/common"
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/controllers"
)

func main() {
	tokenStr := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IjExMUBnbWFpbC5jb20iLCJleHAiOjE2NzgyNzM4Mjh9.7Qy6jh5L1qvVVbOZYR3JrmWdothI2SCF-oGyC2BfZDs"
	reqJSON := common.ReqGenImg{
		UserToken:     tokenStr,
		Prompt:        "iron man skiing on steep slope, hd, high quality",
		NegativePromt: "FastNegativeV2, (low quality:1.3),(worst quality:1.3),(monochrome:0.8),(deformed:1.3),(malformed hands:1.4),(poorly drawn hands:1.4),(mutated fingers:1.4),(bad anatomy:1.3),(extra limbs:1.35),(poorly drawn face:1.4),(watermark:1.3),ugly,watermark,jpeg artifacts,error,text,username",
	}
	result, err := controllers.GenImg(reqJSON)
	...
}
```

{% endtab %}
{% endtabs %}

## SDXL GenAI&#x20;

Generating an image by SDXL mode.

<mark style="color:orange;">`POST`</mark> `https://www.phoenix.global/sdk/computation/genAI/genImgSDXL`

#### Headers

| Name                                    | Type   | Description                              |
| --------------------------------------- | ------ | ---------------------------------------- |
| token<mark style="color:red;">\*</mark> | string | The token generated in the previous step |

#### Request Body

| Name                                     | Type   | Description     |
| ---------------------------------------- | ------ | --------------- |
| prompt<mark style="color:red;">\*</mark> | string | Prompt          |
| negative\_prompt                         | string | Negative prompt |

#### Response

{% tabs %}
{% tab title="200 OK: Return the task ID" %}

```json
{
  "code": 200,
  "msg": "success",
  "task_id": "40a5a249-xxxx-11ef-9ede-0618df6e77e0",
  "token_cost": 1024,  //The number of tokens consumed by this request
  "token_balance": 137542  //The remaining number of tokens
}
```

{% endtab %}
{% endtabs %}

#### CURL and Golang SDK

{% tabs %}
{% tab title="cURL" %}

```bash
curl --location 'https://www.phoenix.global/sdk/computation/genAI/genImgSDXL' \
--header 'token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IjExMUBnbWFpbC5jb20iLCJleHAiOjE2NzgyNzM4Mjh9.7Qy6jh5L1qvVVbOZYR3JrmWdothI2SCF-oGyC2BfZDs' \
--header 'Content-Type: application/json' \
--data '{
  "prompt": "iron man skiing on steep slope, hd, high quality",
  "negative_prompt": "ugly,watermark,jpeg artifacts,error,text,username"
}'
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/common"
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/controllers"
)

func main() {
	tokenStr := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IjIyMkBnbWFpbC5jb20iLCJleHAiOjE3Mjk1ODUzMDZ9.33a-TNCliMkXA8xbrMUh6mokzXVjlo1GLKQPC8bGdPk"
	reqJSON := common.ReqGenImgSDXL{
		UserToken:     tokenStr,
		Prompt:        "iron man skiing on steep slope, hd, high quality",
		NegativePromt: "FastNegativeV2, (low quality:1.3),(worst quality:1.3),(monochrome:0.8),(deformed:1.3),(malformed hands:1.4),(poorly drawn hands:1.4),(mutated fingers:1.4),(bad anatomy:1.3),(extra limbs:1.35),(poorly drawn face:1.4),(watermark:1.3),ugly,watermark,jpeg artifacts,error,text,username",
	}
	result, err := controllers.GenImgSDXL(reqJSON)
	...
}
```

{% endtab %}
{% endtabs %}

## Flux GenAI

Generating an image by Flux mode.

<mark style="color:orange;">`POST`</mark> `https://www.phoenix.global/sdk/computation/genAI/genImgFlux`

#### Headers

| Name                                    | Type   | Description                              |
| --------------------------------------- | ------ | ---------------------------------------- |
| token<mark style="color:red;">\*</mark> | string | The token generated in the previous step |

#### Request Body

| Name                                     | Type   | Description |
| ---------------------------------------- | ------ | ----------- |
| prompt<mark style="color:red;">\*</mark> | string | Prompt      |

#### Response

{% tabs %}
{% tab title="200 OK: Return the task ID" %}

```json
{
  "code": 200,
  "msg": "success",
  "task_id": "40a5a249-xxxx-11ef-9ede-0618df6e77e0",
  "token_cost": 1024,  //The number of tokens consumed by this request
  "token_balance": 137542  //The remaining number of tokens
}
```

{% endtab %}
{% endtabs %}

#### CURL and Golang SDK

{% tabs %}
{% tab title="cURL" %}

```bash
curl --location 'https://www.phoenix.global/sdk/computation/genAI/genImgFlux' \
--header 'token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IjExMUBnbWFpbC5jb20iLCJleHAiOjE2NzgyNzM4Mjh9.7Qy6jh5L1qvVVbOZYR3JrmWdothI2SCF-oGyC2BfZDs' \
--header 'Content-Type: application/json' \
--data '{
  "prompt": "iron man skiing on steep slope, hd, high quality"
}'
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/common"
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/controllers"
)

func main() {
	tokenStr := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IjExMUBnbWFpbC5jb20iLCJleHAiOjE2NzgyNzM4Mjh9.7Qy6jh5L1qvVVbOZYR3JrmWdothI2SCF-oGyC2BfZDs"
	reqJSON := common.ReqGenImgFlux{
		UserToken: tokenStr,
		Prompt:    "iron man skiing on steep slope, hd, high quality",
	}
	result, err := controllers.GenImgFlux(reqJSON)
	...
}
```

{% endtab %}
{% endtabs %}

## Text to Motion

Generating a gif from prompts.

{% hint style="info" %}
**Good to know:** Generating motion may take a long time. It is recommended to use **WSS** to obtain task results.
{% endhint %}

<mark style="color:orange;">`POST`</mark> `https://www.phoenix.global/sdk/computation/genAI/txt2Motion`

#### Headers

| Name                                    | Type   | Description                              |
| --------------------------------------- | ------ | ---------------------------------------- |
| token<mark style="color:red;">\*</mark> | string | The token generated in the previous step |

#### Request Body

| Name                                     | Type   | Description     |
| ---------------------------------------- | ------ | --------------- |
| prompt<mark style="color:red;">\*</mark> | string | Prompt          |
| negative\_prompt                         | string | Negative prompt |

#### Response

{% tabs %}
{% tab title="200 OK: Return the task ID" %}

```json
{
  "code": 200,
  "msg": "success",
  "task_id": "40a5a249-xxxx-11ef-9ede-0618df6e77e0",
  "token_cost": 1024,  //The number of tokens consumed by this request
  "token_balance": 137542  //The remaining number of tokens
}
```

{% endtab %}
{% endtabs %}

#### CURL and Golang SDK

{% tabs %}
{% tab title="cURL" %}

```sh
curl --location 'https://www.phoenix.global/sdk/computation/LLM/callTextToMotion' \
--header 'token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IjExMUBnbWFpbC5jb20iLCJleHAiOjE2NzgyNzM4Mjh9.7Qy6jh5L1qvVVbOZYR3JrmWdothI2SCF-oGyC2BfZDs' \
--header 'Content-Type: application/json' \
--data '{
    "prompt": "a flying phoenix",
    "negative_prompt": "blurry"
}'
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
  "github.com/PhoenixGlobal/Phoenix-Computation-SDK/common"
  "github.com/PhoenixGlobal/Phoenix-Computation-SDK/controllers"
)

func main() {
  tokenStr := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IjExMUBnbWFpbC5jb20iLCJleHAiOjE2NzgyNzM4Mjh9.7Qy6jh5L1qvVVbOZYR3JrmWdothI2SCF-oGyC2BfZDs"
  reqBody := common.ReqTxt2Motion{
    Prompt:        "a flying phoenix",
    NegativePromt: "FastNegativeV2, (low quality:1.3),(worst quality:1.3),(monochrome:0.8),(deformed:1.3),(malformed hands:1.4),(poorly drawn hands:1.4),(mutated fingers:1.4),(bad anatomy:1.3),(extra limbs:1.35),(poorly drawn face:1.4),(watermark:1.3),ugly,watermark,jpeg artifacts,error,text,username",
    UserToken:     tokenStr,
  }
  result, err := controllers.Txt2Motion(reqBody)
  ...
}
```

{% endtab %}
{% endtabs %}

## Image to Motion

Generating a gif from an image

<mark style="color:orange;">`POST`</mark> `https://genapi.phoenix.global/sdk/computation/genAI/img2Motion`

**Headers**

| Name                                    | Type   | Description                              |
| --------------------------------------- | ------ | ---------------------------------------- |
| Token<mark style="color:red;">\*</mark> | string | The token generated in the previous step |

#### Request Body

| Name                                          | Type   | Description |
| --------------------------------------------- | ------ | ----------- |
| image\_path<mark style="color:red;">\*</mark> | string | Image URL   |
| prompt<mark style="color:red;">\*</mark>      | string | Prompt      |

#### **Response**

{% tabs %}
{% tab title="200 OK: Return the task ID" %}

```json
{
  "code": 200,
  "msg": "success",
  "task_id": "40a5a249-xxxx-11ef-9ede-0618df6e77e0",
  "token_cost": 1024,  //The number of tokens consumed by this request
  "token_balance": 137542  //The remaining number of tokens
}
```

{% endtab %}
{% endtabs %}

#### CURL and Golang SDK

{% tabs %}
{% tab title="cURL" %}

```sh
curl --location 'https://www.phoenix.global/sdk/computation/genAI/img2Motion' \
--header 'token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IjExMUBnbWFpbC5jb20iLCJleHAiOjE2NzgyNzM4Mjh9.7Qy6jh5L1qvVVbOZYR3JrmWdothI2SCF-oGyC2BfZDs' \
--header 'Content-Type: application/json' \
--data-raw '{
    "prompt": "a flying phoenix",
    "img_url": "https://phoenix.global/ai/files/LLM/333@gmail.com/phoenix.jpg"
}'
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/common"
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/controllers"
)

func main() {
	tokenStr := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IjIyMkBnbWFpbC5jb20iLCJleHAiOjE3Mjk2Nzg4MTZ9.O_DTemJ5byY_bytXVhfrGWUvZqkH5QvI03OuKpNjces"
	reqBody := common.ReqImg2Motion{
		ImagePath: "https://phoenix.global/ai/files/LLM/333@gmail.com/phoenix.jpg",
		Prompt:    "a flying phoenix",
		UserToken: tokenStr,
	}
	result, err := controllers.Img2Motion(reqBody)
	...
}

```

{% endtab %}
{% endtabs %}

## CogVideo

Generating a gif by CogVideo mode

<mark style="color:orange;">`POST`</mark> `https://genapi.phoenix.global/sdk/computation/genAI/cogVideo`

**Headers**

| Name                                    | Type   | Description                              |
| --------------------------------------- | ------ | ---------------------------------------- |
| Token<mark style="color:red;">\*</mark> | string | The token generated in the previous step |

#### Request Body

| Name                                     | Type   | Description |
| ---------------------------------------- | ------ | ----------- |
| prompt<mark style="color:red;">\*</mark> | string | Prompt      |

#### **Response**

{% tabs %}
{% tab title="200 OK: Return the task ID" %}

```json
{
  "code": 200,
  "msg": "success",
  "task_id": "40a5a249-xxxx-11ef-9ede-0618df6e77e0",
  "token_cost": 1024,  //The number of tokens consumed by this request
  "token_balance": 137542  //The remaining number of tokens
}
```

{% endtab %}
{% endtabs %}

#### CURL and Golang SDK

{% tabs %}
{% tab title="cURL" %}

```sh
curl --location 'https://www.phoenix.global/sdk/computation/genAI/cogVideo' \
--header 'token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IjExMUBnbWFpbC5jb20iLCJleHAiOjE2NzgyNzM4Mjh9.7Qy6jh5L1qvVVbOZYR3JrmWdothI2SCF-oGyC2BfZDs' \
--header 'Content-Type: application/json' \
--data-raw '{
    "prompt": "a flying phoenix",
}'
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/common"
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/controllers"
)

func main() {
	tokenStr := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IjExMUBnbWFpbC5jb20iLCJleHAiOjE2NzgyNzM4Mjh9.7Qy6jh5L1qvVVbOZYR3JrmWdothI2SCF-oGyC2BfZDs"
	reqBody := common.ReqCogVideo{
		UserToken: tokenStr,
		Prompt:    "a flying phoenix",
	}
	result, err := controllers.CogVideo(reqBody)
	...
}
```

{% endtab %}
{% endtabs %}

## Pyramid

Generating a gif by Pyramid mode

<mark style="color:orange;">`POST`</mark> `https://genapi.phoenix.global/sdk/computation/genAI/pyramid`

**Headers**

| Name                                    | Type   | Description                              |
| --------------------------------------- | ------ | ---------------------------------------- |
| Token<mark style="color:red;">\*</mark> | string | The token generated in the previous step |

#### Request Body

| Name                                     | Type   | Description |
| ---------------------------------------- | ------ | ----------- |
| prompt<mark style="color:red;">\*</mark> | string | Prompt      |

#### **Response**

{% tabs %}
{% tab title="200 OK: Return the task ID" %}

```json
{
  "code": 200,
  "msg": "success",
  "task_id": "40a5a249-xxxx-11ef-9ede-0618df6e77e0",
  "token_cost": 1024,  //The number of tokens consumed by this request
  "token_balance": 137542  //The remaining number of tokens
}
```

{% endtab %}
{% endtabs %}

#### CURL and Golang SDK

{% tabs %}
{% tab title="cURL" %}

```sh
curl --location 'https://www.phoenix.global/sdk/computation/genAI/pyramid' \
--header 'token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IjExMUBnbWFpbC5jb20iLCJleHAiOjE2NzgyNzM4Mjh9.7Qy6jh5L1qvVVbOZYR3JrmWdothI2SCF-oGyC2BfZDs' \
--header 'Content-Type: application/json' \
--data-raw '{
    "prompt": "a flying phoenix",
}'
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/common"
	"github.com/PhoenixGlobal/Phoenix-Computation-SDK/controllers"
)

func main() {
	tokenStr := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6IjExMUBnbWFpbC5jb20iLCJleHAiOjE2NzgyNzM4Mjh9.7Qy6jh5L1qvVVbOZYR3JrmWdothI2SCF-oGyC2BfZDs"
	reqBody := common.ReqPyramid{
		UserToken: tokenStr,
		Prompt:    "a flying phoenix",
	}
	result, err := controllers.Pyramid(reqBody)
	...
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://computation-sdk.phoenix.global/reference/api-reference/phoenixgenai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
