# RPGGO API: the AI Engine for Game

Welcome to RPGGO Public API documentation site!

> Edit Easily, Deploy in Seconds, Rendering in Realtime
>
> <mark style="color:green;">Why we work in this field?</mark> [Initial Vision 2023: Text-To-OpenWorld Engine](/dev-docs/thesis/initial-vision-2023-text-to-openworld-engine)

## What's in the API

RPGGO's API offers customized AI structure and features needed for games, especially with multi-NPCs / multi-Chapters / Game Goal Structures:&#x20;

* *AI-powered Characters (AI NPCs)*
* *AI-powered Goal Checking System*
* *Realtime Multi-modal AI*
  * [x] *Image*
  * [x] *Voice Chat*
  * [ ] *Audio Effect (coming soon)*
* *Powering Game in Real-time Online under a general Game structure.*
* *Server-Sent Events asynchronous push*

## See What Fits Your Need

* Read [Getting Started](/dev-docs/introduction/getting-started) and see cases we listed to see if our API is a great fit of your current/potential product.&#x20;

{% content-ref url="/pages/Tq5JEcq3NKI0PJNZ41FH" %}
[Getting Started](/dev-docs/introduction/getting-started)
{% endcontent-ref %}

* RPGGO's API is a modularized product, which meets AI NCP / AI Chapter Switch / AI Goal Check demands for.

<table data-view="cards"><thead><tr><th></th><th></th><th></th><th></th></tr></thead><tbody><tr><td><mark style="color:blue;"><strong>Professional Game Studios</strong></mark></td><td><mark style="color:blue;"><strong>Indie Game Developers / Individual Developers</strong></mark></td><td><ul><li>Power your NPCs</li><li>Switch stages for your story in chapters and phases, from individual impacts to world impacts</li><li>Power goal check with an AI GM</li></ul></td><td></td></tr><tr><td><mark style="color:green;"><strong>App Developer</strong></mark></td><td><mark style="color:green;"><strong>Light-weight Interactive Experience with AI</strong></mark></td><td><ul><li>Build your game and get metadata into your app</li><li>Embed our game into your app / product format</li></ul><p><em>Use case</em></p><p><a data-mention href="/dev-docs/open-source-use-cases/step-by-step-discord-with-v1-api">Step by Step: Discord with V1 API</a></p></td><td></td></tr><tr><td><mark style="color:purple;"><strong>Web Widget Embed</strong></mark></td><td><ul><li>Incoming feature</li></ul></td><td><mark style="color:purple;"><strong>Non-developer Just Interested in Turning Your Idea into an H5 Game</strong></mark></td><td><ul><li>Use Creator Tool and see your game published on web in seconds</li><li>Creator Tool for UGC <a href="https://creator.rpggo.ai/">https://creator.rpggo.ai</a></li></ul></td></tr></tbody></table>

## &#x20;See How to Use:&#x20;

{% content-ref url="/pages/dL7k17j7dhYj8tXwpzmj" %}
[Player API](/dev-docs/player-api/api-overview)
{% endcontent-ref %}

* [API Overview](/dev-docs/player-api/api-overview)
* [API V2 (New)](/dev-docs/player-api/api-overview/api-v2-new) - The most recent version of RPGGO API
  * [API V1 (Deprecated)](/dev-docs/player-api/api-overview/api-v1-deprecated)
* [Understand the data schema](/dev-docs/data-schema/understand-the-data-schema)

## Apply Your Test Key

* RPGGO Public API is in currently under **alpha phase** and do not open to auto-public application.&#x20;
* If you want to try it, please submit an application form via [here](https://forms.gle/sw9kqPQNfBDcnya6A), or send an email to <mark style="background-color:yellow;"><dev@rpggo.ai></mark>

{% content-ref url="/pages/9ZEowCG4134gZ6Y6er5B" %}
[Apply Your Test Key](/dev-docs/support/apply-your-test-key)
{% endcontent-ref %}

{% content-ref url="/pages/FD6HbE8E7LpZFkDtEMBX" %}
[Contact us](/dev-docs/support/contact-us)
{% endcontent-ref %}


# Getting Started

Start from here and see which best describes your need.

{% content-ref url="/pages/dL7k17j7dhYj8tXwpzmj" %}
[Player API](/dev-docs/player-api/api-overview)
{% endcontent-ref %}

## Professional Game Studio

> If you are from **professional game studio** and look for an AI engine to integrate within your game as shown in the video...&#x20;
>
> Turning your game into AI-powered RPG in seconds, let your 3D assets become intelligent interactive parts and extend your game depth.

* You might use RPGGO AI engine to power stories under worldview, rendering story and character conversations, conduct chapter / phases changes in real-time
  1. Integrate in to the **3D assets** you've built and the game you've developed with UE/Unity Engine
  2. Let RPGGO powers the AI side of your **role-playing part**
  3. Send customized requests to our API and trigger the actions of AI NPCs
* This API might not fit all your needs. Normally working with 3A professional game studio's game needs to be well crafted and requires 3-5 months  of customization works including:
  * [x] IP data pre-processing
  * [x] model fine- tuning
  * [x] NPC optimization
  * [x] content moderation etc.&#x20;
* Contact our PGC business part (<mark style="color:blue;"><pgcbusiness@rpggo.ai></mark>) for support.

{% embed url="<https://youtu.be/WeM33dzFwFg>" %}
Powering 3D Assets with AI-NPCs and Connect with Game Action Flags to Trigger Chapter/Phase Switches
{% endembed %}

## Indie Game Studio / Individual Developer

> If you are from **indie game studio or an individual developer**, and looking for a AI solution to power your game as in the video...

* You might use Edit in Creator Tool first, and request for an API of RPGGO AI engine to power stories under worldview, rendering story and character conversations, conduct chapter / phases changes in real-time
  1. Integrate in to the **2D assets** you've built and the game you've developed with Game Engine
  2. and let RPGGO powers the AI side of your **role-playing part**

{% embed url="<https://youtu.be/zidkLGJnFxU>" %}
Edit Throgh Creator Tool and Integrate APIs into Unity
{% endembed %}

This API is a perfect match to you. We release simple [creator tool ](https://creator.rpggo.ai/)that allow creators quickly customize their story worlds and game setting. After you create your game there, you can integrate this API with your game to make it visual.\
\
Here is an 2D AI Town example code for you to reference:  [2D AI Town with V2 API](/dev-docs/open-source-use-cases/2d-ai-town-with-v2-api). Very simple and you can create your town in 30 mins.

## Game Mod Developer

If you are not a indie game developer, but have interests to integrate your favorite RPGGO game into other AAA game,  you can use our V2 API to build the Mod and bring more fun to your existing game experience.

1. Ingest the RPGGO game via V2 API
2. and let RPGGO AI Engine to bring AI experience into your game path.

{% embed url="<https://youtu.be/zE0sovb_f4U>" %}

In this Stardew Valley example, you will add extra fun of AI RPG without changing existing game experience and logic. Double Fun!

Check out below example for details:

{% content-ref url="/pages/9wEIsQOvo6YVkfpbuWO9" %}
[Stardew Valley Mod with V2 API](/dev-docs/open-source-use-cases/stardew-valley-mod-with-v2-api)
{% endcontent-ref %}

## App Developer - Light weight interactive AI Experience

> If you are **not a game developer, but an app developer**, and want to build light-weight interactive experience with AI to pleasure your users in telegram, discord, botim, wechat etc. as below

This API is also a perfect match to you. You don't need to build any game by yourself since we already have plenty of games in our platform.&#x20;

* Please send email to our <mark style="color:blue;">UGC business part(<ugcbusiness@rpggo.ai>)</mark>  to get permission with your api key. And then you can have our games in your app as well.

{% embed url="<https://youtu.be/D0OTsZUmML4>" %}
Integrate in Discord Channel and Let the Bots Become AI Game NPCs for a Specific Game
{% endembed %}

## Web Channel owner/ Blogger

> If you want to add other's game into your website and bring more fun to your viewers.

We have "Games Everywhere" prepared for you, where you can embed existing AI-native games into your website. Go to [Game Lobby ](https://rpggo.ai/)to find the game which fits your website, and copy the game URL or game ID. Then, go to [Games Everywhere](https://rpggo.ai/embed), and follow the instruction to get the embed code.

<figure><img src="https://1241690067-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FChXuEllR7kvvuUM9K1Fi%2Fuploads%2FRHLfSbAt6WwrAnZgwIXA%2Fimage.png?alt=media&amp;token=da8129e7-f003-45d6-956b-42d2dcb5dc31" alt=""><figcaption><p>Embed AI-native game in your own web</p></figcaption></figure>

## I Want to Have a Web AI Game!

> If you are not a developer, but want to turn your interesting idea to a H5 game.&#x20;

Great, you don't need to any code work, and we build the one-stop solution for you. Go to [creator tool](https://creator.rpggo.ai/), after building your idea there, click the player button. You will see your game in web and easy to share with your friends in either PC or Mobile

<figure><img src="https://1241690067-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FChXuEllR7kvvuUM9K1Fi%2Fuploads%2FRdC30bB2DW2jWLNol65j%2FUntitled%20design%20(21).png?alt=media&amp;token=8d3c446f-845b-480b-80be-e23b15dc4906" alt=""><figcaption><p>Make your first web AI RPG!</p></figcaption></figure>

## Some more details about RPGGO?

> If you are none of above roles, but just curious about what we are doing,&#x20;

Our [Blog](https://blog.rpggo.ai) might have more info you interested.


# Understand the data schema

How it functions?

> You can interact with the API through HTTP requests from any language, For ease of use and comprehension, here are some key concepts and data flows within RPGGO. Understanding these will help you rapidly build your own AI-native app.

## RPGGO is a role-play game framework built around AI.&#x20;

To integrate concepts from both gaming and storytelling, we've designed four fundamental elements: ***games***, ***scenes***, ***goals***, and ***NPCs*** to assist you in crafting your open-world experience.

<figure><img src="https://1241690067-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FChXuEllR7kvvuUM9K1Fi%2Fuploads%2F7i9uiQF3RwbSreQSgrCc%2Fwhiteboard_exported_image.png?alt=media&amp;token=b6204ff5-dee9-4860-b8bf-09405ad46506" alt=""><figcaption><p>Key Concepts</p></figcaption></figure>

* <mark style="background-color:blue;">**Game**</mark>: A complete gaming experience, which can encompass multiple scenes, using various scenes to enrich perspectives and clues, facilitating a progressive storytelling approach.
* <mark style="background-color:blue;">**Scene**</mark> <mark style="color:blue;">**(Chapter in V2)**</mark><mark style="color:blue;">:</mark> A specific location or scenario within the game. Each scene contains one or more goals. When all goals are achieved, the game transitions to the next scene for further exploration.
* <mark style="background-color:blue;">**Goal**</mark>: Specific goals within a scene that players must accomplish. These goals often require dialogue with NPCs to obtain clues necessary for completion. Typically, multiple goals will progressively uncover deeper clues to aid players.
* <mark style="background-color:blue;">**NPC**</mark>**&#x20;**<mark style="color:blue;">**(Character in V2)**</mark>: Individuals or observers present in a scene. Additionally, each scene requires a DM to assist in advancing the game or handling unexpected situations. Players can freely interact with NPCs to gather clues or just for fun.

## In summary, users can engage in conversations with NPCs to acquire information while the "DM" will oversee the game

* Users can submit answers and reasoning to the DM to achieve next goal set within a scene.&#x20;
* Once all goals in a scene are completed, the game progresses to the next scene, at which point goals and NPCs may have undergone new changes.&#x20;
* Victory in the game is achieved when all scene goals are met.
* *Bad endings are under designed, which is based on value checks, and this will be released soon, more detailed controls and multi storylines can be made from the creator side easily.*

For schema details , go to next chapter.

{% content-ref url="/pages/d9ZYL7sCXdRZKCJe5O4Q" %}
[🪿LLM-based Game Open Schema (L-GOS)](/dev-docs/data-schema/llm-based-game-open-schema-l-gos)
{% endcontent-ref %}

<br>


# 🪿LLM-based Game Open Schema (L-GOS)

https\://github.com/RPGGO-AI/l-gos-spec

I pronounce 'L-GOS' as "Large Goose" :)

<figure><img src="https://1241690067-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FChXuEllR7kvvuUM9K1Fi%2Fuploads%2FDfT0c8k8CXsK6IjQiwyf%2Fimage.png?alt=media&amp;token=7ca89db7-1d2f-40c0-9eb1-b406259aa38f" alt=""><figcaption></figcaption></figure>

The vision of RPGGO is to democratize game creation together with UGC creators. This means that UGC creators have full copyright ownership of their games and the freedom to transfer them to any third-party platform. This is why we create this L-GOS open schema and fully compatible with it.

This L-GOS project aims to define an open data schema that any third-party LLM gaming platform can easily support and be compatible with. This way, UGC game creators can import and run their games on any third-party LLM gaming platform.

\
Our RPGGO backend is fully compatible with this open schema approach, facilitating more flexible and interoperable API connections. This open schema enables developers to integrate and extend functionalities with ease, offering a robust foundation for innovative applications and services. By adopting this model, we aim to streamline data exchange and improve overall system efficiency, ultimately enhancing the user experience.

So, once you jump into our API doc, please spend a few minutes to understand the data schema first, which will help you to deal our API with ease.

* \[Game]\(<https://github.com/RPGGO-AI/l-gos-spec/blob/main/schema_v1/game_v1.md>)
* \[Characrer]\(<https://github.com/RPGGO-AI/l-gos-spec/blob/main/schema_v1/character_v1.md>)
* \[Module]\(<https://github.com/RPGGO-AI/l-gos-spec/blob/main/schema_v1/module_v1.md>)

> Only with the support of more and more third-party platforms can a truly decentralized gaming ecosystem emerge. \
> \
> If your company or service is compatible with this schema, please let us know.


# V2 API

The V2 API is still under developing. We plan to add game creation, character creation, module creation and game assets generation here.


# Create Character

Creating a minimalist Solo-Character.

### 1. Create a character with L-GOS schema

> Note we only accepts the character data on L-GOS schema.

`POST` <https://api.rpggo.ai/v2/character/create>

**Request Body**

same as <https://github.com/RPGGO-AI/l-gos-spec/blob/main/schema_v1/character_v1.md>

<table><thead><tr><th>Name</th><th>Type</th><th width="137">Example Value</th><th>Description</th></tr></thead><tbody><tr><td>name</td><td>String</td><td>"📒 Sample: Dungeon Master"</td><td></td></tr><tr><td>avatar_url</td><td>String</td><td>"https://a.com/xxx.jpg"</td><td>http image url</td></tr><tr><td>background</td><td>String</td><td>"Play a text-based dungeon crawler game. You are the game designer, dungeon master, and host for the game session. I am The player. use the DND 5E system."</td><td></td></tr><tr><td>appearance</td><td>String</td><td>"A dungeon master"</td><td></td></tr><tr><td>traits</td><td>Array</td><td>["Confident", "Creative", "Drama"]</td><td></td></tr><tr><td>tone</td><td>Array</td><td>["Drama"]</td><td></td></tr><tr><td>intro</td><td>String</td><td>"Welcome to my Tavern, Traveler. This is the DND 5E playground."</td><td></td></tr><tr><td>tags</td><td>Array</td><td>["Male", "Game", "Serious", "Narration"]</td><td>See the tags definitions  here: [L-GOS Tags](<a href="https://github.com/RPGGO-AI/l-gos-spec/blob/main/schema_v1/tag_v1.md">https://github.com/RPGGO-AI/l-gos-spec/blob/main/schema_v1/tag_v1.md</a>)<br><br>Just fill in the value under the specific type, case-insensitive<br><br>Only one value can be selected for each type</td></tr><tr><td>opening_line</td><td>String</td><td>"I'm thrilled to be your Dungeon Master for this thrilling journey. Before we begin, let me clarify a few things. Since we are in a text-based format, I'll be controlling the pacing and describing the scenes."</td><td></td></tr><tr><td>creator</td><td>String</td><td>"Your-RPGGO-ID"</td><td>It must be your own user ID, otherwise the character will not appear in your creator tool list</td></tr><tr><td>creator_notes</td><td>String</td><td>""</td><td></td></tr><tr><td>modules</td><td>Array</td><td>[]</td><td>Not supported yet, can be null</td></tr><tr><td>publish_status</td><td>String</td><td>"opensource"</td><td>Optional parameters： opensource published unpublished</td></tr></tbody></table>

{% code title="Sample Curl" lineNumbers="true" %}

```bash
curl --location --request POST 'https://api.rpggo.ai/v2/character/create' \
--header 'Authorization: YOUR-API-KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
  {
    "name": "📒 Sample: Dungeon Master",
    "avatar_url": "xxx.jpg",
    "background": "Play a text-based dungeon crawler game. You are the game designer,  dungeon master, and host for the game session. I am The player. use the DND 5E system.",
    "appearance": "A dungeon master",
    "traits": [
        "Confident",
        "Creative",
        "Drama"
    ],
    "tone": [
        "Drama"
    ],
    "intro": "Welcome to my Tavern, Traveler. This is the DND 5E playground.",
    "tags": [
        "Male",
        "Game",
        "Serious",
        "Narration"
    ],
    "opening_line": "Im thrilled to be your Dungeon Master for this thrilling journey. Before we begin, let me clarify a few things. Since we are in a text-based format, will be controlling the pacing and describing the scenes.",
    "creator": "my_rpggo_user_id",
    "creator_notes": "",
    "modules": [],
    "publish_status": "opensource"
  }
}'
```

{% endcode %}

{% tabs %}
{% tab title="200: OK " %}
{% code lineNumbers="true" %}

```json
{
    "code": 200,
    "message": "success",
    "data": "CN8J7VFR5OB"
}
```

{% endcode %}
{% endtab %}

{% tab title="10000008: Unauthorized " %}

```json
{
    "code": 10000008,
    "message": "Authentication failed，Invalid token"
}
```

{% endtab %}

{% tab title="10000000: Low balance" %}

```json
{​
    "code": 10000000,​
    "message": "user balance is not enough"​
}
```

{% endtab %}
{% endtabs %}

After creating the character succesfully, you will be able to see your character in the \[Creator Tool]\(<https://creator.rpggo.ai/>)

<figure><img src="https://1241690067-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FChXuEllR7kvvuUM9K1Fi%2Fuploads%2FBMnAyMEEtV5MvwDdh7F2%2Fimage.png?alt=media&amp;token=fc6719ae-609d-46d6-9c01-92b5e70ab356" alt=""><figcaption></figcaption></figure>


# Create Game SpriteSheet

Creating a 2D pixel art for your game.

The SpriteSheet Generation API allows developers to generate AI-powered 2D pixel-style spritesheets for use in game engines. By providing a textual prompt, the API will return a spritesheet in the requested style and format.

<figure><img src="https://storage.googleapis.com/rpggo-gameassets/CharacterSheet/4216a20242d342d092798c144aeeb803_G.png" alt=""><figcaption><p>Super Mario, Sheet</p></figcaption></figure>

<figure><img src="https://storage.googleapis.com/rpggo-imagegen/CHARACTER_SHEET/55b65302b14c4ebb9ba8e5737c28ca0c.gif" alt=""><figcaption><p>Super Mario, gif</p></figcaption></figure>

<figure><img src="https://storage.googleapis.com/rpggo-gameassets/CharacterSheet/b4cce51a8da64910987d623fb9b151aa_G.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://storage.googleapis.com/rpggo-imagegen/CHARACTER_SHEET/bd4d4612e6a8446cac796c97fba2824c.gif" alt=""><figcaption><p>Pikachu, gif</p></figcaption></figure>

### 1. Endpoint

```
POST https://api.rpggo.ai/v2/assets/spritesheet/create

```

### **2. Request Body**

<table><thead><tr><th>Name</th><th>Type</th><th width="137">Example Value</th><th>Description</th></tr></thead><tbody><tr><td>style</td><td>String</td><td>"v1"</td><td>Two versions available ["v1", "v2"]. Default is v1. </td></tr><tr><td>form</td><td>String</td><td>"sheet"</td><td>Tow formats available ["sheet", "gif"]. Default is "sheet", for game engine use case. "gif" is more suitable for profile, avatar needs.</td></tr><tr><td>prompt</td><td>String</td><td>"Super Mario in snow cloth"</td><td>Describe the appearance of the sprite sheet. Default is "", which means for a random generation.</td></tr><tr><td>scale_by</td><td>int</td><td>2</td><td>tile size of the sprite sheet. Default is 2.</td></tr></tbody></table>

<br>

> Note, you need to fill in your own api key in the curl. For how to apply api key, [Apply Your Test Key](/dev-docs/support/apply-your-test-key)

{% code title="Sample Curl" lineNumbers="true" %}

```bash
curl --location 'https://api.rpggo.ai/v2/assets/spritesheet/create' \
--header 'Content-Type: application/json' \
--header 'Authorization: YOUR-API-KEY' \
--data '{
    "style": "v1",
    "prompt": "a girl",
    "form": "sheet",
    "scale_by": 2
}'
```

{% endcode %}

{% tabs %}
{% tab title="200: OK " %}
{% code lineNumbers="true" %}

```json
{
    "code": 200,
    "msg": "ok",
    "data": {
        "img_url": "https://storage.googleapis.com/rpggo-imagegen/CHARACTER_SHEET/54d9b5f8d25d4a1991eb2d2f26cdaa3f.gif"
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="10000008: Unauthorized " %}

```json
{
    "code": 10000008,
    "message": "Authentication failed，Invalid token"
}
```

{% endtab %}

{% tab title="10000000: Low balance" %}

```json
{​
    "code": 10000000,​
    "message": "user balance is not enough"​
}
```

{% endtab %}
{% endtabs %}

### **Rate Limits**

* each api call will spend 30 GG coins. Make sure you have balance in your account.


# API Overview

The description of V2 of APIs powered by RPGGO's AI engine

## Data Schema

> The Rendering Basis of your Game

{% content-ref url="/pages/M1dtqsT4rHDaTugU2b1Q" %}
[Understand the data schema](/dev-docs/data-schema/understand-the-data-schema)
{% endcontent-ref %}

* [Understand the data schema](/dev-docs/data-schema/understand-the-data-schema) and knows how to integrate into your product and drive the movement of your characters

## :gear: <mark style="color:purple;">API V2 Details</mark>

Check the developer doc for what you can build with RPGGO's AI Engine

{% content-ref url="/pages/HTF25OKMaXbZooEmusvb" %}
[API V2 (New)](/dev-docs/player-api/api-overview/api-v2-new)
{% endcontent-ref %}

## Interested In Accessing? Apply Now

{% content-ref url="/pages/9ZEowCG4134gZ6Y6er5B" %}
[Apply Your Test Key](/dev-docs/support/apply-your-test-key)
{% endcontent-ref %}

## Create a Game and Get GameID to Test

Edit in Creator Tool, and Get the Game Url as ID

> This is an open platform free for editing and making games, designed for game script writers and newbies who are not familiar with game designs.

* [Creator Tool](https://creator.rpggo.ai/) - The UGC Platform of RPGGO
* RPGGO Creator Tool Video tutorial: [RPGGO Tutorial: How to Create A RPG on My Own Using AI? Introduction to Creator Tool](https://www.youtube.com/watch?v=QzzZ22o54Vc)

## What's in API V1:

{% content-ref url="/pages/F7oJXUQVfV7Ump63nTeV" %}
[API V1 (Deprecated)](/dev-docs/player-api/api-overview/api-v1-deprecated)
{% endcontent-ref %}


# API V2 (New)

Fetch Game, Set Control, Integrate Characters, Chat in SSE, Manage User Goal Check with AI Released on May 11, 2024.

## Part 1. Data Schema&#x20;

{% content-ref url="/pages/M1dtqsT4rHDaTugU2b1Q" %}
[Understand the data schema](/dev-docs/data-schema/understand-the-data-schema)
{% endcontent-ref %}

If you've read [Understand the data schema](/dev-docs/data-schema/understand-the-data-schema) already, in V2 API, we renamed "Scene" to "Chapter", and "NPC" to "Character".

## Part 2. Game Control - Manage the User Experience in Game

* Get Game Data
* Start Game
* Switch Chapters
* Continue Sessions (Game progress memory)

{% content-ref url="/pages/RIeEzH0QHIehue7FN6FT" %}
[Game Control](/dev-docs/player-api/api-overview/api-v2-new/game-control)
{% endcontent-ref %}

## Part 3. Chat with NPCs & Check Goal with SSE - What's in SSE

* Chat with NPCs in SSE (single chat, group chat)
* Normal NPC Conversations
* Game Control Messages AI Powered Goal Check

{% content-ref url="/pages/cgYpBaNNMeU7HLkS3H5S" %}
[Chat with NPCs & Check Goal with SSE](/dev-docs/player-api/api-overview/api-v2-new/chat-with-npcs-and-check-goal-with-sse)
{% endcontent-ref %}

* **Async via SSE:** V1 provides synced api call only. But V2, we turn to async msg push, which means all the generation will be pushed to client via SSE.

## Part 4. Multi-modal Output

* V2 support image, audio, music generation in real-time.&#x20;
* Currently its a whitelist logic under gameid, request for multi-modal game experience by sending us your GameId, <mark style="color:blue;"><dev@rpggo.ai></mark>
* Sample game for Multi-modal output <https://rpggo.ai/game/25e19be0-2b17-47e9-9891-d12a7131506b#/game?gameId=25e19be0-2b17-47e9-9891-d12a7131506b>

## Part 5. Game List Authorization

* You can only access permission-granted games.
* Let us know if you are interested in any GameId or a GameId list.  send request to <mark style="color:blue;"><dev@rpggo.ai></mark>

## Part 6. Sample Code

* Here is an example of node.js to play with our V2 API.  [Simple Chat Game with V2 API](/dev-docs/open-source-use-cases/simple-chat-game-with-v2-api)

<br>


# Game Control

Fetch Game, Start Game, Change Chapters while Goal Check Triggers, Resume with Memories

### 1. Get metadata of a specific game

retrieve the game basic information for preview

`POST` <https://api.rpggo.ai/v2/open/game/gamemetadata>&#x20;

**Request Body**

| Name     | Type   | Description               |
| -------- | ------ | ------------------------- |
| game\_id | String | the unique id of the game |

{% code title="Sample Curl" lineNumbers="true" %}

```bash
curl --location 'https://api.rpggo.ai/v2/open/game/gamemetadata' \
--header 'accept: application/json' \
--header 'Authorization:$YOUR_RPGGO_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
  "game_id": "42d029a8-b5a7-49cb-94f4-8baefb0b898a"
}'
```

{% endcode %}

{% tabs %}
{% tab title="200: OK " %}
{% code lineNumbers="true" %}

```json
{
    "code": 0,
    "msg": "ok",
    "data": {
        "name": "📒 BAC -Break the boundaries",
        "game_id": "42d029a8-b5a7-49cb-94f4-8baefb0b898a",
        "background": "",
        "intro": "In 2102, Terminus City has clear class divides, with Mega Corporation ruling. Rebels in the Wild Hope District challenge this after a drone crash.",
        "image": "https://storage.googleapis.com/rpggo-game/rpggo-creator/5c642a81-e09a-4349-b3a2-f00156479dff/9cc4b0a4-6bfa-489a-aee8-57217a2c5cfd",
        "genre": "published",
        "user_id": "",
        "moderation_level": "",
        "background_musics": null,
        "chapters": [
            {
                "name": "The Crash",
                "chapter_id": "da08c8ff-490e-4a7f-853c-c64d8c803b15",
                "background": "Prologue - Marco (you,Player), an underground street racer from the Wild Hope District, is born with a restless nature flowing in his blood, and his sister Chiara seems equally rebellious under his influence.\n\nChiara connected her consciousness to a drone and infiltrated Terminus, but unfortunately, the drone crashed midway. The accident caused severe neurological trauma to Chiara, and angry Marco swore to find the culprit.\n\nhint:\n(Ask each character who they are)\n(Ask each character what happened before and after the accident)\n(Ask each character if they helped Chiara)\n(Ask each character the cause of the accident)",
                "intro": "None",
                "image": "",
                "background_audio": "",
                "ending_audio": ""
            }
        ],
        "interaction": null,
        "created_at": "2024-03-13T04:53:43Z",
        "updated_at": "2024-04-25T04:41:56Z"
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}
{% endtabs %}

### 2. Start the game

start the game at specific chapter. If chapter\_id is not specified, then start from chapter 1.

`POST` <https://api.rpggo.ai/v2/open/game/startgame>

**Request Body**

| Name        | Type   | Description                                                                                               |
| ----------- | ------ | --------------------------------------------------------------------------------------------------------- |
| game\_id    | String | the unique id of the game                                                                                 |
| chapter\_id | String | the unique id of the start chapter                                                                        |
| session\_id | String | the unique id to identify the play session. The API Caller need to maintian the session\_id in its logic. |

{% code title="Sample Curl" lineNumbers="true" %}

```bash
curl --location 'https://api.rpggo.ai/v2/open/game/startgame' \
--header 'accept: application/json' \
--header 'Authorization:$YOUR_RPGGO_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
  "game_id": "42d029a8-b5a7-49cb-94f4-8baefb0b898a",
  "session_id": "42d029a8sdrrwqd"
}'
```

{% endcode %}

{% tabs %}
{% tab title="200: OK " %}
{% code lineNumbers="true" %}

```json
{
    "code": 0,
    "msg": "ok",
    "data": {
        "name": "📒 BAC -Break the boundaries",
        "game_id": "42d029a8-b5a7-49cb-94f4-8baefb0b898a",
        "background": "",
        "intro": "In 2102, Terminus City has clear class divides, with Mega Corporation ruling. Rebels in the Wild Hope District challenge this after a drone crash.",
        "image": "https://storage.googleapis.com/rpggo-game/rpggo-creator/5c642a81-e09a-4349-b3a2-f00156479dff/9cc4b0a4-6bfa-489a-aee8-57217a2c5cfd",
        "genre": "published",
        "user_id": "ed10dbe4-7b90-46b8-9d8c-49acbca791ee",
        "chapter": {
            "name": "The Crash",
            "chapter_id": "da08c8ff-490e-4a7f-853c-c64d8c803b15",
            "background": "Prologue - Marco (you,Player), an underground street racer from the Wild Hope District, is born with a restless nature flowing in his blood, and his sister Chiara seems equally rebellious under his influence.\n\nChiara connected her consciousness to a drone and infiltrated Terminus, but unfortunately, the drone crashed midway. The accident caused severe neurological trauma to Chiara, and angry Marco swore to find the culprit.\n\nhint:\n(Ask each character who they are)\n(Ask each character what happened before and after the accident)\n(Ask each character if they helped Chiara)\n(Ask each character the cause of the accident)",
            "intro": "None",
            "image": "",
            "background_audio": "",
            "ending_audio": "",
            "characters": [
                {
                    "id": "7ed2dfa5-bcbc-4621-b2bd-dc0d0555811e",
                    "name": "Chiara",
                    "type": "dm",
                    "avatar": "https://storage.googleapis.com/rpggo-game/rpggo-creator/24fd170e-5116-41c8-8d93-57b148d50e42/6bb48ef3-9da7-4e6b-88a6-cc297a0e2987",
                    "phases": [
                        "default"
                    ]
                },
                {
                    "id": "ea1858ce-5317-4689-b940-742dbe0919c8",
                    "name": "Luca",
                    "type": "npc",
                    "avatar": "https://storage.googleapis.com/rpggo-game/rpggo-creator/c47caf17-2a05-44c5-a494-47683b40aef3/f38a1fea-d364-4ee0-b7d7-fb45d9c42593",
                    "phases": [
                        "default"
                    ]
                },
                {
                    "id": "cb3059a6-3fba-4dc9-a1b0-f20e6bb4e9ec",
                    "name": "Alessio",
                    "type": "npc",
                    "avatar": "https://storage.googleapis.com/rpggo-game/rpggo-creator/f73cd10c-23a0-4dc2-88ad-9663d3b54c1d/7b8842a0-13d7-4668-a268-67d6eb1099df",
                    "phases": [
                        "default"
                    ]
                },
                {
                    "id": "6032b7f2-b514-409e-9a65-bcceb975daa8",
                    "name": "Giulia",
                    "type": "npc",
                    "avatar": "https://storage.googleapis.com/rpggo-game/rpggo-creator/fe88083b-6221-4550-9dc9-8f5cbb395946/ce26fd17-e78e-4ded-94f8-0b0f29c33d8e",
                    "phases": [
                        "default"
                    ]
                },
                {
                    "id": "4a5a365f-23ac-443e-9f3d-0ca59b913d15",
                    "name": "Francesca",
                    "type": "npc",
                    "avatar": "https://storage.googleapis.com/rpggo-game/rpggo-creator/f7cbf80b-7f3f-4b7b-9e23-587d07135f67/fde545d3-a3ec-48d6-810f-b6e90bcf0b92",
                    "phases": [
                        "default"
                    ]
                }
            ]
        },
        "created_at": "2024-03-13T04:53:43Z",
        "updated_at": "2024-04-25T04:41:56Z"
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}
{% endtabs %}

### &#x20;3. Switch chapter

switch the current chapter to other chapter.

`POST` <https://api.rpggo.ai/v2/open/game/changechapter>

**Request Body**

| Name        | Type   | Description                                                                                               |
| ----------- | ------ | --------------------------------------------------------------------------------------------------------- |
| game\_id    | String | the unique id of the game                                                                                 |
| chapter\_id | String | the unique id of the start chapter                                                                        |
| session\_id | String | the unique id to identify the play session. The API Caller need to maintian the session\_id in its logic. |

{% code title="Sample Curl" lineNumbers="true" %}

```bash
curl --location 'https://api.rpggo.ai/v2/open/game/changechapter' \
--header 'accept: application/json' \
--header 'Authorization:$YOUR_RPGGO_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
  "game_id": "42d029a8-b5a7-49cb-94f4-8baefb0b898a",
  "chapter_id": "da08c8ff-490e-4a7f-853c-c64d8c803b15",
  "session_id": "42d029a8sdrrwqd"
}'
```

{% endcode %}

{% tabs %}
{% tab title="200: OK " %}
{% code lineNumbers="true" %}

```json
{
    "code": 0,
    "msg": "ok",
    "data": {
        "name": "📒 BAC -Break the boundaries",
        "game_id": "42d029a8-b5a7-49cb-94f4-8baefb0b898a",
        "background": "",
        "intro": "In 2102, Terminus City has clear class divides, with Mega Corporation ruling. Rebels in the Wild Hope District challenge this after a drone crash.",
        "image": "https://storage.googleapis.com/rpggo-game/rpggo-creator/5c642a81-e09a-4349-b3a2-f00156479dff/9cc4b0a4-6bfa-489a-aee8-57217a2c5cfd",
        "genre": "published",
        "user_id": "ed10dbe4-7b90-46b8-9d8c-49acbca791ee",
        "chapter": {
            "name": "The Crash",
            "chapter_id": "da08c8ff-490e-4a7f-853c-c64d8c803b15",
            "background": "Prologue - Marco (you,Player), an underground street racer from the Wild Hope District, is born with a restless nature flowing in his blood, and his sister Chiara seems equally rebellious under his influence.\n\nChiara connected her consciousness to a drone and infiltrated Terminus, but unfortunately, the drone crashed midway. The accident caused severe neurological trauma to Chiara, and angry Marco swore to find the culprit.\n\nhint:\n(Ask each character who they are)\n(Ask each character what happened before and after the accident)\n(Ask each character if they helped Chiara)\n(Ask each character the cause of the accident)",
            "intro": "None",
            "image": "",
            "background_audio": "",
            "ending_audio": "",
            "background_musics": null,
            "characters": [
                {
                    "id": "7ed2dfa5-bcbc-4621-b2bd-dc0d0555811e",
                    "name": "Chiara",
                    "type": "dm",
                    "avatar": "https://storage.googleapis.com/rpggo-game/rpggo-creator/24fd170e-5116-41c8-8d93-57b148d50e42/6bb48ef3-9da7-4e6b-88a6-cc297a0e2987",
                    "phases": [
                        "default"
                    ]
                },
                {
                    "id": "ea1858ce-5317-4689-b940-742dbe0919c8",
                    "name": "Luca",
                    "type": "npc",
                    "avatar": "https://storage.googleapis.com/rpggo-game/rpggo-creator/c47caf17-2a05-44c5-a494-47683b40aef3/f38a1fea-d364-4ee0-b7d7-fb45d9c42593",
                    "phases": [
                        "default"
                    ]
                },
                {
                    "id": "cb3059a6-3fba-4dc9-a1b0-f20e6bb4e9ec",
                    "name": "Alessio",
                    "type": "npc",
                    "avatar": "https://storage.googleapis.com/rpggo-game/rpggo-creator/f73cd10c-23a0-4dc2-88ad-9663d3b54c1d/7b8842a0-13d7-4668-a268-67d6eb1099df",
                    "phases": [
                        "default"
                    ]
                },
                {
                    "id": "6032b7f2-b514-409e-9a65-bcceb975daa8",
                    "name": "Giulia",
                    "type": "npc",
                    "avatar": "https://storage.googleapis.com/rpggo-game/rpggo-creator/fe88083b-6221-4550-9dc9-8f5cbb395946/ce26fd17-e78e-4ded-94f8-0b0f29c33d8e",
                    "phases": [
                        "default"
                    ]
                },
                {
                    "id": "4a5a365f-23ac-443e-9f3d-0ca59b913d15",
                    "name": "Francesca",
                    "type": "npc",
                    "avatar": "https://storage.googleapis.com/rpggo-game/rpggo-creator/f7cbf80b-7f3f-4b7b-9e23-587d07135f67/fde545d3-a3ec-48d6-810f-b6e90bcf0b92",
                    "phases": [
                        "default"
                    ]
                }
            ]
        },
        "created_at": "2024-03-13T04:53:43Z",
        "updated_at": "2024-04-25T04:41:56Z"
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}
{% endtabs %}

### 4. Resume the game from a previous session

if user want to continue the playing from a previous session

`POST` <https://api.rpggo.ai/v2/open/game/resumesession>

**Request Body**

| Name        | Type   | Description                                                                                               |
| ----------- | ------ | --------------------------------------------------------------------------------------------------------- |
| game\_id    | String | the unique id of the game                                                                                 |
| session\_id | String | the unique id to identify the play session. The API Caller need to maintian the session\_id in its logic. |

{% code title="Sample Curl" overflow="wrap" lineNumbers="true" %}

```bash
curl --location 'https://api.rpggo.ai/v2/open/game/resumesession' \
--header 'accept: application/json' \
--header 'Authorization:$YOUR_RPGGO_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
  "game_id": "42d029a8-b5a7-49cb-94f4-8baefb0b898a",
  "session_id": "42d029a8sdrrwqd"
}'
```

{% endcode %}

{% tabs %}
{% tab title="200: OK " %}
{% code lineNumbers="true" %}

```json
{
    "code": 0,
    "msg": "ok",
    "data": {
        "name": "📒 BAC -Break the boundaries",
        "game_id": "42d029a8-b5a7-49cb-94f4-8baefb0b898a",
        "background": "",
        "intro": "In 2102, Terminus City has clear class divides, with Mega Corporation ruling. Rebels in the Wild Hope District challenge this after a drone crash.",
        "image": "https://storage.googleapis.com/rpggo-game/rpggo-creator/5c642a81-e09a-4349-b3a2-f00156479dff/9cc4b0a4-6bfa-489a-aee8-57217a2c5cfd",
        "genre": "published",
        "user_id": "ed10dbe4-7b90-46b8-9d8c-49acbca791ee",
        "chapter": {
            "name": "The Crash",
            "chapter_id": "da08c8ff-490e-4a7f-853c-c64d8c803b15",
            "background": "Prologue - Marco (you,Player), an underground street racer from the Wild Hope District, is born with a restless nature flowing in his blood, and his sister Chiara seems equally rebellious under his influence.\n\nChiara connected her consciousness to a drone and infiltrated Terminus, but unfortunately, the drone crashed midway. The accident caused severe neurological trauma to Chiara, and angry Marco swore to find the culprit.\n\nhint:\n(Ask each character who they are)\n(Ask each character what happened before and after the accident)\n(Ask each character if they helped Chiara)\n(Ask each character the cause of the accident)",
            "intro": "None",
            "image": "",
            "background_audio": "",
            "ending_audio": "",
            "characters": [
                {
                    "id": "7ed2dfa5-bcbc-4621-b2bd-dc0d0555811e",
                    "name": "Chiara",
                    "type": "dm",
                    "avatar": "https://storage.googleapis.com/rpggo-game/rpggo-creator/24fd170e-5116-41c8-8d93-57b148d50e42/6bb48ef3-9da7-4e6b-88a6-cc297a0e2987",
                    "phases": [
                        "default"
                    ]
                },
                {
                    "id": "ea1858ce-5317-4689-b940-742dbe0919c8",
                    "name": "Luca",
                    "type": "npc",
                    "avatar": "https://storage.googleapis.com/rpggo-game/rpggo-creator/c47caf17-2a05-44c5-a494-47683b40aef3/f38a1fea-d364-4ee0-b7d7-fb45d9c42593",
                    "phases": [
                        "default"
                    ]
                },
                {
                    "id": "cb3059a6-3fba-4dc9-a1b0-f20e6bb4e9ec",
                    "name": "Alessio",
                    "type": "npc",
                    "avatar": "https://storage.googleapis.com/rpggo-game/rpggo-creator/f73cd10c-23a0-4dc2-88ad-9663d3b54c1d/7b8842a0-13d7-4668-a268-67d6eb1099df",
                    "phases": [
                        "default"
                    ]
                },
                {
                    "id": "6032b7f2-b514-409e-9a65-bcceb975daa8",
                    "name": "Giulia",
                    "type": "npc",
                    "avatar": "https://storage.googleapis.com/rpggo-game/rpggo-creator/fe88083b-6221-4550-9dc9-8f5cbb395946/ce26fd17-e78e-4ded-94f8-0b0f29c33d8e",
                    "phases": [
                        "default"
                    ]
                },
                {
                    "id": "4a5a365f-23ac-443e-9f3d-0ca59b913d15",
                    "name": "Francesca",
                    "type": "npc",
                    "avatar": "https://storage.googleapis.com/rpggo-game/rpggo-creator/f7cbf80b-7f3f-4b7b-9e23-587d07135f67/fde545d3-a3ec-48d6-810f-b6e90bcf0b92",
                    "phases": [
                        "default"
                    ]
                }
            ]
        },
        "created_at": "2024-03-13T04:53:43Z",
        "updated_at": "2024-04-25T04:41:56Z"
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}
{% endtabs %}


# Chat with NPCs & Check Goal with SSE

## SSE Chat (Single Chat & Group Chat, Memory Share)

To chat with different characters, the client need to start a SSE call to receive msg.

`POST`[`https://api.rpggo.ai/v2/open/game/chatsse`](https://api.rpggo.ai/v2/open/game/chatsse)&#x20;

**Request Body**

| Name            | Type       | Description                               |
| --------------- | ---------- | ----------------------------------------- |
| game\_id        | String     | the unique id of the game                 |
| session\_id     | String     | the unique id of the game session         |
| character\_id   | String     | the unique id of the character            |
| message\_id     | String     | any unique id to identify the msg         |
| message         | String     | the message content                       |
| advance\_config | dictionary | config to enable the image, voice output. |

**Header**

| Name          | Type   | Description                                                               |
| ------------- | ------ | ------------------------------------------------------------------------- |
| Authorization | String | Bearer Token [Apply Your Test Key](/dev-docs/support/apply-your-test-key) |
| Content-Type  | String | application/json                                                          |

#### Normal Conversation Request

{% code title="Sample Curl" lineNumbers="true" %}

```bash
curl --location 'https://api.rpggo.ai/v2/open/game/chatsse' \
--header 'accept: application/json' \
--header 'Authorization:$YOUR_RPGGO_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
  "character_id": "0b2d7f6b-cf8b-4bca-9aec-da8236ffb40a",
  "game_id": "42d029a8-b5a7-49cb-94f4-8baefb0b898a",
  "message": "hi",
  "message_id": "b5fasdffx",
  "session_id": "42d029a8sdrrwqd"
}'
```

{% endcode %}

#### Normal Conversation Message

{% tabs %}
{% tab title="200: OK " %}
{% code lineNumbers="true" %}

```json
fin
data
{"ret":200,"message":"success","data":{"result":{"character_id":"goal_check_dm","character_type":"goal_check_dm","image":"","text":"","text_ext":"","epoch":{"current_count":0,"max_chat_count":0},"insiders":[],"message_id":"b5fasdffxef"},"game_status":{"game_id":"42d029a8-b5a7-49cb-94f4-8baefb0b898a","goal_id":"","goal":{"chapter_tip":{"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","closing_statement":""},"goals_status":[]},"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","action":0,"action_message":"","game_meta":{"shared_memory":{"goal_check_dm_epoch":1}},"chapters_map":["da08c8ff-490e-4a7f-853c-c64d8c803b15"]}}}
data
{"ret":200,"message":"success","data":{"result":{"character_id":"7ed2dfa5-bcbc-4621-b2bd-dc0d0555811e","character_type":"common_npc","image":"","text":"Hey there! *(smiling)* What's up? 😊","text_ext":"","epoch":{"current_count":1,"max_chat_count":90},"insiders":["7ed2dfa5-bcbc-4621-b2bd-dc0d0555811e","ea1858ce-5317-4689-b940-742dbe0919c8","cb3059a6-3fba-4dc9-a1b0-f20e6bb4e9ec","6032b7f2-b514-409e-9a65-bcceb975daa8","4a5a365f-23ac-443e-9f3d-0ca59b913d15"],"message_id":"b5fasdffxef"},"game_status":{"game_id":"42d029a8-b5a7-49cb-94f4-8baefb0b898a","goal_id":"goals0","goal":{"chapter_tip":{"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","closing_statement":""},"goals_status":[]},"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","action":0,"action_message":"","game_meta":{},"chapters_map":[]}}}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}
{% endtabs %}

#### Multimodal Conversation Request

{% code title="Sample Curl" lineNumbers="true" %}

```bash
curl --location 'https://api.rpggo.ai/v2/open/game/chatsse' \
--header 'accept: application/json' \
--header 'Authorization: ' \
--header 'Content-Type: application/json' \
--data {
  "game_id": "42d029a8-b5a7-49cb-94f4-8baefb0b898a",
  "character_id": "7ed2dfa5-bcbc-4621-b2bd-dc0d0555811e",
  "message": "Can you tell me more about what you saw through the drone? 📡",
  "user_id": "6bad72e7-a936-4069-84f8-670540cf3cac",
  "session_id": "2Kzoxbeht_aoHNgDeHLtN",
  "message_id": "lkxQ8yGzbklVp3DwlHWQH",
  "advance_config": {
    "enable_image_streaming": true
  }
}'
```

{% endcode %}

#### Multimodal Conversation Message

{% tabs %}
{% tab title="200: OK " %}
{% code lineNumbers="true" %}

```json
fin
data
{"ret":200,"message":"success","data":{"result":{"character_id":"picture_produce_dm","character_type":"picture_produce_dm","image":"https://storage.googleapis.com/rpggo-imagegen/42d029a8-b5a7-49cb-94f4-8baefb0b898a/f28452f5a91b4ce687d56c0c08cd454f.jpeg","image_type":1,"text":"With a spark of excitement in her eyes, Chiara leans in, recounting her close encounter—a shadowy figure adorned with a familiar emblem, hinting at connections to the racing underworld.","text_ext":"","epoch":{"current_count":0,"max_chat_count":0},"insiders":[],"message_id":"lkxQ8yGzbklVp3DwlHWQH","log_id":"10077ae2-637b-4558-979e-ceb3880fbb46","action_list":[]},"game_status":{"game_id":"42d029a8-b5a7-49cb-94f4-8baefb0b898a","goal_id":"","goal":{"chapter_tip":{"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","closing_statement":""},"goals_status":[]},"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","action":0,"action_message":"","game_meta":{},"chapters_map":["da08c8ff-490e-4a7f-853c-c64d8c803b15"],"displayed_status":{},"multimodal":{"action":2,"action_message":"picture produce sync"}},"transaction_details":{"ImageConsumption":{"type":"ImageConsumption","amount":4,"fund_direction":"OUT","name":"Image Streaming","description":"Create breathtaking Al-generated images that bring thegame's plot to life."}}}}
data
{"ret":200,"message":"success","data":{"result":{"character_id":"goal_check_dm","character_type":"goal_check_dm","image":"","text":"","text_ext":"","epoch":{"current_count":0,"max_chat_count":0},"insiders":[],"message_id":"b5fasdffxef"},"game_status":{"game_id":"42d029a8-b5a7-49cb-94f4-8baefb0b898a","goal_id":"","goal":{"chapter_tip":{"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","closing_statement":""},"goals_status":[]},"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","action":0,"action_message":"","game_meta":{"shared_memory":{"goal_check_dm_epoch":1}},"chapters_map":["da08c8ff-490e-4a7f-853c-c64d8c803b15"]}}}
data
{"ret":200,"message":"success","data":{"result":{"character_id":"7ed2dfa5-bcbc-4621-b2bd-dc0d0555811e","character_type":"common_npc","image":"","text":"Hey there! *(smiling)* What's up? 😊","text_ext":"","epoch":{"current_count":1,"max_chat_count":90},"insiders":["7ed2dfa5-bcbc-4621-b2bd-dc0d0555811e","ea1858ce-5317-4689-b940-742dbe0919c8","cb3059a6-3fba-4dc9-a1b0-f20e6bb4e9ec","6032b7f2-b514-409e-9a65-bcceb975daa8","4a5a365f-23ac-443e-9f3d-0ca59b913d15"],"message_id":"b5fasdffxef"},"game_status":{"game_id":"42d029a8-b5a7-49cb-94f4-8baefb0b898a","goal_id":"goals0","goal":{"chapter_tip":{"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","closing_statement":""},"goals_status":[]},"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","action":0,"action_message":"","game_meta":{},"chapters_map":[]}}}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}
{% endtabs %}

## Game Control Message

#### 1. Chapter Switch

| character\_type | message field                | value  | command note            |
| --------------- | ---------------------------- | ------ | ----------------------- |
| goal\_check\_dm | data.game\_status.action     | 2      | switch chapter          |
| common\_npc     | game\_status.action\_message | string | the new chapter content |

{% tabs %}
{% tab title="200: OK " %}
{% code lineNumbers="true" %}

```json
fin
data
{"ret":200,"message":"success","data":{"result":{"character_id":"goal_check_dm","character_type":"goal_check_dm","image":"","text":"","text_ext":"","epoch":{"current_count":0,"max_chat_count":0},"insiders":[],"message_id":"b5fasdffxef"},"game_status":{"game_id":"42d029a8-b5a7-49cb-94f4-8baefb0b898a","goal_id":"","goal":{"chapter_tip":{"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","closing_statement":""},"goals_status":[]},"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","action":2,"action_message":"","game_meta":{"shared_memory":{"goal_check_dm_epoch":1}},"chapters_map":["da08c8ff-490e-4a7f-853c-c64d8c803b15"]}}}
data
{"ret":200,"message":"success","data":{"result":{"character_id":"7ed2dfa5-bcbc-4621-b2bd-dc0d0555811e","character_type":"common_npc","image":"","text":"Hey there! *(smiling)* What's up? 😊","text_ext":"","epoch":{"current_count":1,"max_chat_count":90},"insiders":["7ed2dfa5-bcbc-4621-b2bd-dc0d0555811e","ea1858ce-5317-4689-b940-742dbe0919c8","cb3059a6-3fba-4dc9-a1b0-f20e6bb4e9ec","6032b7f2-b514-409e-9a65-bcceb975daa8","4a5a365f-23ac-443e-9f3d-0ca59b913d15"],"message_id":"b5fasdffxef"},"game_status":{"game_id":"42d029a8-b5a7-49cb-94f4-8baefb0b898a","goal_id":"goals0","goal":{"chapter_tip":{"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","closing_statement":""},"goals_status":[]},"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","action":0,"action_message":"","game_meta":{},"chapters_map":[]}}}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}
{% endtabs %}

#### 2. Game Ending

| character\_type | message field                | value  | command note       |
| --------------- | ---------------------------- | ------ | ------------------ |
| goal\_check\_dm | data.game\_status.action     | 3      | Game is ending     |
| common\_npc     | game\_status.action\_message | string | The ending summary |

{% tabs %}
{% tab title="200: OK " %}
{% code lineNumbers="true" %}

```json
fin
data
{"ret":200,"message":"success","data":{"result":{"character_id":"goal_check_dm","character_type":"goal_check_dm","image":"","text":"","text_ext":"","epoch":{"current_count":0,"max_chat_count":0},"insiders":[],"message_id":"b5fasdffxef"},"game_status":{"game_id":"42d029a8-b5a7-49cb-94f4-8baefb0b898a","goal_id":"","goal":{"chapter_tip":{"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","closing_statement":""},"goals_status":[]},"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","action":3,"action_message":"","game_meta":{"shared_memory":{"goal_check_dm_epoch":1}},"chapters_map":["da08c8ff-490e-4a7f-853c-c64d8c803b15"]}}}
data
{"ret":200,"message":"success","data":{"result":{"character_id":"7ed2dfa5-bcbc-4621-b2bd-dc0d0555811e","character_type":"common_npc","image":"","text":"Hey there! *(smiling)* What's up? 😊","text_ext":"","epoch":{"current_count":1,"max_chat_count":90},"insiders":["7ed2dfa5-bcbc-4621-b2bd-dc0d0555811e","ea1858ce-5317-4689-b940-742dbe0919c8","cb3059a6-3fba-4dc9-a1b0-f20e6bb4e9ec","6032b7f2-b514-409e-9a65-bcceb975daa8","4a5a365f-23ac-443e-9f3d-0ca59b913d15"],"message_id":"b5fasdffxef"},"game_status":{"game_id":"42d029a8-b5a7-49cb-94f4-8baefb0b898a","goal_id":"goals0","goal":{"chapter_tip":{"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","closing_statement":""},"goals_status":[]},"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","action":0,"action_message":"","game_meta":{},"chapters_map":[]}}}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}
{% endtabs %}

#### 3. Failed to pass game

| character\_type | message field                        | value  | command note                  |
| --------------- | ------------------------------------ | ------ | ----------------------------- |
| goal\_check\_dm | data.game\_status.action             | 4      | Fail the goal                 |
| common\_npc     | goal.chapter\_tip.closing\_statement | string | The ending summary of failure |

{% tabs %}
{% tab title="200: OK " %}
{% code lineNumbers="true" %}

```json
fin
data
{"ret":200,"message":"success","data":{"result":{"character_id":"goal_check_dm","character_type":"goal_check_dm","image":"","text":"","text_ext":"","epoch":{"current_count":0,"max_chat_count":0},"insiders":[],"message_id":"b5fasdffxef"},"game_status":{"game_id":"42d029a8-b5a7-49cb-94f4-8baefb0b898a","goal_id":"","goal":{"chapter_tip":{"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","closing_statement":"The goal is 'zingbagaly' failed."},"goals_status":[{"goal":"The goal is 'zinbagaly' failed.","goal_id":"fail_goal","achieved":true}]},"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","action":4,"action_message":"","game_meta":{"shared_memory":{"goal_check_dm_epoch":1}},"chapters_map":["da08c8ff-490e-4a7f-853c-c64d8c803b15"]}}}
data
{"ret":200,"message":"success","data":{"result":{"character_id":"7ed2dfa5-bcbc-4621-b2bd-dc0d0555811e","character_type":"common_npc","image":"","text":"Hey there! *(smiling)* What's up? 😊","text_ext":"","epoch":{"current_count":1,"max_chat_count":90},"insiders":["7ed2dfa5-bcbc-4621-b2bd-dc0d0555811e","ea1858ce-5317-4689-b940-742dbe0919c8","cb3059a6-3fba-4dc9-a1b0-f20e6bb4e9ec","6032b7f2-b514-409e-9a65-bcceb975daa8","4a5a365f-23ac-443e-9f3d-0ca59b913d15"],"message_id":"b5fasdffxef"},"game_status":{"game_id":"42d029a8-b5a7-49cb-94f4-8baefb0b898a","goal_id":"goals0","goal":{"chapter_tip":{"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","closing_statement":""},"goals_status":[]},"chapter_id":"da08c8ff-490e-4a7f-853c-c64d8c803b15","action":0,"action_message":"","game_meta":{},"chapters_map":[]}}}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}
{% endtabs %}

#### 4. Other error messages

{% tabs %}
{% tab title="200: OK " %}
{% code lineNumbers="true" %}

```json
err
{"ret":10000303,"message":"The game session has ended","data":null}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="200: OK " %}
{% code lineNumbers="true" %}

```json
err
{"ret":10000307,"message":"Data error. Please refresh the page or restart the game","data":null}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}
{% endtabs %}


# API V1 (Deprecated)

<mark style="color:red;">Released on Nov 11, 2023, and stop to support since Dec 31, 2024.</mark>

Dive into the specifics of each API endpoint by checking out our complete documentation.

## Game

Everything related to Game:

{% content-ref url="/pages/LYt6KC68hWrhHVllnadR" %}
[Game](/dev-docs/player-api/api-overview/api-v1-deprecated/game)
{% endcontent-ref %}

## NPC

Everything related to NPCs:

{% content-ref url="/pages/jiOmi8f2fcJKimBOWpLE" %}
[NPC](/dev-docs/player-api/api-overview/api-v1-deprecated/npc)
{% endcontent-ref %}

## Memory

{% content-ref url="/pages/7apstp7uICfRfukqMISO" %}
[Memory](/dev-docs/player-api/api-overview/api-v1-deprecated/memory)
{% endcontent-ref %}

## ErrorCode

{% content-ref url="/pages/XFwXHS2Z83sj5zw7eht3" %}
[ErrorCode](/dev-docs/player-api/api-overview/api-v1-deprecated/errorcode)
{% endcontent-ref %}


# Game

## List Games (V1 Only)

### Lists the currently available games, and provides basic information about each one such as the owner and availability. <a href="#lists-the-currently-available-games-and-provides-basic-information-about-each-one-such-as-the-owner" id="lists-the-currently-available-games-and-provides-basic-information-about-each-one-such-as-the-owner"></a>

`POST` `https://api.rpggo.ai/open/game/gamelist`

**Request Body**

| Name     | Type   | Description                                                  |
| -------- | ------ | ------------------------------------------------------------ |
| category | String | the category of games, will return all the games by default. |

{% tabs %}
{% tab title="200: OK " %}

```json
{
  "code": 0,
  "msg": "ok",
  "data": {
    "game_list": [
      {
        "id": 1,
        "name": "Midnight Manor, A Killer Among Us",
        "background": "background of game1",
        "intro": "In the midst of your presence in a castle, a murder unfolds...",
        "image": "https://storage.googleapis.com/rpggo_images/website/logo.svg",
        "scenes": [
          {
            "id": 1,
            "name": "Midnight Scene1",
            "background": "A snowy night in 1903, in an old castle on the outskirts of London..."
            "intro": "scene1 intro",
            "image": "https://storage.googleapis.com/rpggo_images/website/logo.svg"
          },
          {
            "id": 2,
            "name": "Midnight Scene2",
            "background": "A snowy night in 1903..."
            "intro": "scene2 intro",
            "image": "https://storage.googleapis.com/rpggo_images/website/logo.svg"
          }
        ]
      },
      {
        "id": 2,
        "name": "Fatal Palette: The Enigma of the Vanishing Sunflowers",
        "background": "John's lifeless body lay just steps away from where Van Gogh's masterpiece once graced the wall...",
        "intro": "John's lifeless body lay just steps away...",
        "image": "",
        "scenes": [
          {
            "id": 27,
            "name": "scene1",
            "background": "the painting has disappeared without a trace...",
            "intro": "Was it a murder, or did he fall victim to natural causes...",
            "image": "https://storage.googleapis.com/rpggo_images/website/logo.svg"
          }
        ]
      }
    ]
  }
}
```

{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}
{% endtabs %}

## Start a new game

## Start  a new game.

<mark style="color:green;">`POST`</mark> `https://api.rpggo.ai/open/game/startgame`&#x20;

#### Request Body

| Name                                          | Type   | Description                                                                                           |
| --------------------------------------------- | ------ | ----------------------------------------------------------------------------------------------------- |
| session\_id<mark style="color:red;">\*</mark> | String | game session's unique ID, which records the current game state and conversation history.              |
| game\_id<mark style="color:red;">\*</mark>    | String | game ID, obtainable through the /gamelist API.                                                        |
| scene\_id<mark style="color:red;">\*</mark>   | String | scene ID, obtainable through the /gamelist API.  Ensure that this scene is in the corresponding game. |

{% tabs %}
{% tab title="200: OK " %}

```json
{
  "code": 0,
  "msg": "ok",
  "data": {
    "id": 22,
    "name": "Midnight Manor, A Killer Among Us",
    "background": "background of game22",
    "intro": "In the midst of your presence in a castle, a murder unfolds...",
    "image": "https://storage.googleapis.com/rpggo_images/website/logo.svg",
    "scene": {
      "id": 27,
      "name": "home",
      "background": "the painting has disappeared without a trace...",
      "intro": "Was it a murder, or did he fall victim to natural causes...",
      "image": "https://storage.googleapis.com/rpggo_images/website/logo.svg"
      "init_dialog": [
        {
          "npc_id": "1168130113938931712",
          "id": 124,
          "name": "Oswald",
          "message": "hi, I am Oswald.",
          "llm": false,
          "index": 0
        },
        {
          "npc_id": "1168129586136092682",
          "id": 123,
          "name": "Painter-Ceres",
          "message": "hi, I am Painter.",
          "llm": false,
          "index": 1
        }
      ],
      "npcs": [
        {
          "id": "1161661128770850867",
          "name": "Dungeon Master",
          "type": "dm"
        },
        {
          "id": "1168130113938931712",
          "name": "Oswald",
          "type": "npc"
        },
        {
          "id": "1168129586136092682",
          "name": "Painter-Ceres",
          "type": "npc"
        }
      ]
    }
  }
}
```

{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}
{% endtabs %}

## Change scene and continue the game

## Switch to the specified scene and continue a new game

<mark style="color:green;">`POST`</mark> `https://api.rpggo.ai/open/game/changescene` &#x20;

#### Request Body

| Name                                          | Type   | Description                                                                                                     |
| --------------------------------------------- | ------ | --------------------------------------------------------------------------------------------------------------- |
| session\_id<mark style="color:red;">\*</mark> | String | current session ID, must be an ongoing game session id                                                          |
| game\_id<mark style="color:red;">\*</mark>    | String | current game ID, obtainable through the /gamelist API.                                                          |
| scene\_id<mark style="color:red;">\*</mark>   | String | specified scene ID, obtainable through the /gamelist API.  Ensure that this scene is in the corresponding game. |

{% tabs %}
{% tab title="200: OK " %}

```json
{
  "code": 0,
  "msg": "ok",
  "data": {
    "id": 22,
    "name": "Midnight Manor, A Killer Among Us",
    "background": "background of game22",
    "intro": "In the midst of your presence in a castle, a murder unfolds...",
    "image": "https://storage.googleapis.com/rpggo_images/website/logo.svg",
    "scene": {
      "id": 27,
      "name": "home",
      "background": "the painting has disappeared without a trace...",
      "intro": "Was it a murder, or did he fall victim to natural causes...",
      "image": "https://storage.googleapis.com/rpggo_images/website/logo.svg"
      "init_dialog": [
        {
          "npc_id": "1168130113938931712",
          "id": 124,
          "name": "Oswald",
          "message": "hi, I am Oswald.",
          "llm": false,
          "index": 0
        },
        {
          "npc_id": "1168129586136092682",
          "id": 123,
          "name": "Painter-Ceres",
          "message": "hi, I am Painter.",
          "llm": false,
          "index": 1
        }
      ],
      "npcs": [
        {
          "id": "1161661128770850867",
          "name": "Dungeon Master",
          "type": "dm"
        },
        {
          "id": "1168130113938931712",
          "name": "Oswald",
          "type": "npc"
        },
        {
          "id": "1168129586136092682",
          "name": "Painter-Ceres",
          "type": "npc"
        }
      ]
    }
  }
}
```

{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}
{% endtabs %}


# NPC

There are two types of NPCs: regular NPCs and DMs.&#x20;

NPCs possess distinct personalities, backgrounds, and in-game roles. Players can interact with them to gather clues.

DMs primarily drive the game's storyline and provide players with information about the current game goals and verification of game outcomes.

## Chat with NPC & DM

## Chat with NPCs or the DM in the game to gather clues or advance the gameplay.

<mark style="color:green;">`POST`</mark> `https://api.rpggo.ai/open/game/chat`&#x20;

#### Request Body

| Name                                          | Type   | Description                                                                              |
| --------------------------------------------- | ------ | ---------------------------------------------------------------------------------------- |
| session\_id<mark style="color:red;">\*</mark> | String | game session's unique ID, which records the current game state and conversation history. |
| npc\_id<mark style="color:red;">\*</mark>     | String | the ID of the NPC or DM you wish to engage in a conversation with.                       |
| message<mark style="color:red;">\*</mark>     | String | chat message                                                                             |

{% tabs %}
{% tab title="200: OK " %}

```json
{
  "code": 0,
  "msg": "ok",
  "data": {
    "result": {
      "image": "",
      "text": "I am James, the loyal butler of Mr. John...",
      "epoch": {
        "current_count": 5,
        "max_chat_count": 10
      }
    },
    "game_status": {
      "game_id": "22",
      "goal_id": "1",
      "scene_id": "2",
      "action": 0
    }
  }
}
```

{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}
{% endtabs %}

When conversing with an NPC, focus on the content of the "result" field in the response.&#x20;

* "text" contains the NPC's textual response, and "image" is reserved for future support of AI-generated images.&#x20;
* To enhance gameplay, each NPC has a limit on the number of chat rounds. Within the "epoch," "max\_chat\_count" represents the maximum dialogue rounds, while "current\_count" tracks the current number of dialogues.

When conversing with the DM, in addition to the previously mentioned details, pay attention to the "game\_status" field for advancing the game. The "action" field indicates the upcoming game state:

* 0 -  remaining in the current goal, requiring the user to continue exploring clues and provide the DM with the correct answers.
* 1  -  moving on to the next goal, indicating that the user has completed the current goal and should proceed to the next one based on the DM's response.

{% hint style="info" %}
Players can obtain the current goal through chat with the DM, so developers don't need to handle this. The DM will automatically inform the player of the next stage's goals.
{% endhint %}

* 2 - moving on to next scene, signifying that the user has successfully completed all objectives within the current scene and is moving on to the next one. You need to initiate a new scene by calling the "[https://api.rpggo.ai/open/game/startgame ](<https://api.rpggo.ai/open/game/startgame >)" API, specifying the "game\_id" and "scene\_id."

{% hint style="info" %}
In the "game\_status," the IDs correspond to the next steps to take. If you need to proceed to the next scene, simply use these IDs.
{% endhint %}

* 3 - indicating that the user has completed all goals in all scenes, successfully finishing the game.


# Memory

The RPGGO game engine automatically performs a series of engineering optimizations and algorithmic recalls on the dialogue history between users and AI to enhance the quality of conversations.&#x20;

Developers have the flexibility to retrieve the raw NPC memory (dialogue history) at any time, allowing them to insert custom dialogues at appropriate intervals to enrich the memory content.

## Get Memory by Session

```bash
curl -X 'POST' \
  'https://api.rpggo.ai/open/game/memory' \
  -H 'accept: application/json' \
  -H 'Application-ID: $YOUR_APPLICATION_ID' \
  -H 'Authorization: $YOUR_BEARER_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "session_id": "$SESSION_ID"
}'
```

## Retrieve the entire conversation history of the current session using the session ID.

<mark style="color:green;">`POST`</mark> `https://api.rpggo.ai/open/game/memory`

#### Request Body

| Name                                          | Type   | Description                                    |
| --------------------------------------------- | ------ | ---------------------------------------------- |
| session\_id<mark style="color:red;">\*</mark> | String | session ID, must be an ongoing game session id |

{% tabs %}
{% tab title="200: OK " %}

```json
{
  "code": 0,
  "msg": "ok",
  "data": {
    "memory_item": [
      {
        "SessionID": "$SESSION_ID",
        "Source": "discord",
        "BotIndex": "1160442433985859738",
        "Message": "How long and often how does this happen with the fridge",
        "Reply": "How long and how often does this happen with the fridge? *(rolls eyes)* Well, it seems like Karen's lunch goes missing quite frequently. Maybe she's just forgetful or someone's got a real appetite for her food. But hey, who knows, maybe it's Lamar with his holy prayers, sneaking a snack when nobody's looking. Or maybe it's Alan, the quiet immigrant driver, trying to make ends meet by taking a bite out of Karen's lunch. *(smirking)* Who knows, right?",
        "Type": 0,
        "CreateTime": "1701139538",
        "UpdateTime": "1701139538"
      },
      {
        "SessionID": "$SESSION_ID",
        "Source": "discord",
        "BotIndex": "1160442433985859738",
        "Message": "Is Lamar Muslim?",
        "Reply": "How would I know if Lamar is Muslim? Do I look like his personal religious advisor? *(rolls eyes)* It's not like he prays in the break room every day or anything. *(sarcastic tone)* But hey, who knows, maybe he's just really committed to his faith and has nothing to do with Karen's missing lunch. Or maybe it's Alan, the starving immigrant driver, who's desperate enough to steal food. *(smirking)* Who knows, right?",
        "Type": 0,
        "CreateTime": "1701139538",
        "UpdateTime": "1701139538"
      }
    ],
    "counters": {
      "1160442433985859738": 2,
      "all": 2
    }
  }
}
```

{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}
{% endtabs %}

Developers can retrieve the complete conversation records of the current session from the `memory_item` array in response.&#x20;

* `botIndex` corresponds to the NPC ID, allowing you to filter memories for a specific NPC using this field.&#x20;
* `message` and `reply` fields represent a user-AI dialogue
* &#x20;`type` field distinguishes memory types. 0 for normal interactions via the llm and 1 for dialogues  stored through the `open/game/recordmemory` API.

## Record Memory

```bash
curl -X 'POST' \
  'https://api.rpggo.ai/open/game/recordmemory' \
  -H 'accept: application/json' \
  -H 'Application-ID: $YOUR_APPLICATION_ID' \
  -H 'Authorization: $YOUR_BEARER_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "session_id": "rs_222531704307449856_1178834756272660602_20_3d529def-d6de-4ac7-989b-ff46dc5ac3ff",
  "chats": [
    {
      "npc_id": "1160442433985859738",
      "message": "hi, this is the user message",
      "reply": "hi, this is the assistant reply"
    },
    {
      "npc_id": "1160442433985859738",
      "message": "hi, this is another user message",
      "reply": "hi, this is the assistant reply"
    }
  ]
}'
```

<mark style="color:green;">`POST`</mark> `https://api.rpggo.ai/open/game/recordmemory`&#x20;

#### Request Body

| Name                                          | Type   | Description                                                      |
| --------------------------------------------- | ------ | ---------------------------------------------------------------- |
| session\_id<mark style="color:red;">\*</mark> | String | session ID, must be an ongoing game session id                   |
| chats<mark style="color:red;">\*</mark>       | List   | A dictionary with three fields: `npc_id`, `message`, and `reply` |

{% tabs %}
{% tab title="200: OK " %}

```json
{
  "code": 0,
  "msg": "successfully saved 2 memories"
}
```

{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}
{% endtabs %}

Before invoking the `recordmemory` API, it is essential to initiate a game to obtain a session id or use an already ongoing game. Memories are recorded in chronological order based on the invocation of the interface, and developers can retrieve them through the  `/open/game/memory` interface.

In the `chats` field, developers can submit one or multiple conversation histories. Each dialogue history consists of three elements:&#x20;

* `npc_id` designates the associated NPC
* `message` and `reply` simulate user and AI interactions


# ErrorCode

## 1  Error Code Description

The RPGGO API error code currently consists of two types:

* Generic base errors
* Chat dialogue errors

## 2 Error Code Data Structure

If the request is incorrect, the server will return the error message in JSON format, the error message contains:

```
{
  "code": 10000301,
  "msg": "You have used up the limit of conversation."
}
```

## 3 Error Code List

### **Generic base errors**

| code     | msg                                                                | Description and Troubleshooting Recommendations                                                                                                             |
| -------- | ------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 10000000 | Internal Server Error                                              | There is an internal error on the server, please request again. If this error persists, please submit a work order in the Baidu Cloud console for feedback. |
| 10000001 | Input Parameter Error                                              | Incorrect format of the entry parameter, e.g. missing required parameters.                                                                                  |
| 10000003 | Authentication failed Unable to find corresponding App information | Please check if the AppId is wrong.                                                                                                                         |
| 10000004 | Authentication failed, Token error                                 | Please check if the token is wrong.                                                                                                                         |
| 10000005 | Authentication failed, Token timeout                               | Please new.                                                                                                                                                 |
|          |                                                                    |                                                                                                                                                             |

### Chat dialogue errors

| code     | msg                                         | Description and Troubleshooting Recommendations       |
| -------- | ------------------------------------------- | ----------------------------------------------------- |
| 10000301 | You have used up the limit of conversation. | Excessive number of dialogues for NPC.                |
| 10000302 | Game session has not exited                 | No game session is bound. Please bind the game first. |
| 10000303 | The game session has ended                  | The game session has ended, please start a new game.  |


# Notes: API V2 Released

We just released our latest V2 API in May 12, 2024. And the legacy V1 API will be continued maintained till the end of this year.

If you are an existing partner with V1 API, we'd suggest you to migrate to our V2 since it brings quite lots of new features including streaming, multi-modal, NPC intelligence, etc. It will improve your game experience significantly!\
\
If you are a newbie, V2 API is your best match!

***See changes between V2 & V1 here***

{% content-ref url="/pages/UWqrnYHSQF0IuapkbZZc" %}
[Changes](/dev-docs/player-api/notes-api-v2-released/changes)
{% endcontent-ref %}


# Changes

Introduction

### 1. schema change

If you read [Understand the data schema](/dev-docs/data-schema/understand-the-data-schema) already, in V2 API, we renamed "Scene" to "Chapter", and "NPC" to "Character".

### 2. sync to async

V1 provides synced api call only. But V2, we turn to async msg push, which means all the generation will be pushed to client via SSE.

### 3. multi-modal

Not only like V1 API to generate text only, V2 support image, audio, music generation in real-time.&#x20;

### 4. authorization change

In V2, API key cannot list games any more. It can only access permission-granted games.

<br>


# Step by Step: Discord with V1 API

Based on our Discord game, here is a basic practice to demonstrate how to create a simple detective game using our API.

{% hint style="info" %}
Before diving into this document, it is strongly recommended to read [here](/dev-docs/data-schema/understand-the-data-schema) to understand the relationships between games, scenes, goals, DMs, and NPCs.
{% endhint %}

> All interfaces require the application of an app ID and authentication. The specific process can be found [here](/dev-docs/support/apply-your-test-key)

## GameList

You need to call the [gamelist interface ](/dev-docs/player-api/api-overview/api-v1-deprecated/game#list-games)to retrieve all playable games. This API will return basic game information, which you can display as needed. In our Discord game, we display the game name and a brief description to help players choose.

Additionally, you need to remember the game ID and scene ID. When starting the game in the next step, the API will require these to specify the game. The relationship between games and scenes can be referenced [here](/dev-docs/data-schema/understand-the-data-schema).

<figure><img src="https://1241690067-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FChXuEllR7kvvuUM9K1Fi%2Fuploads%2Fd4yghvAKFgg5PxAMS21W%2Fbp-1.png?alt=media&amp;token=a6841d74-c150-4b70-841a-e72dba839dc3" alt=""><figcaption></figcaption></figure>

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

```bash
curl --location --request POST 'https://api.rpggo.ai/open/game/gamelist' \
--header 'Application-ID: YOUR_RPGGO_APP_ID' \
--header 'Authorization: Bearer YOUR_RPGGO_API_KEY' \
--data ''
```

{% endtab %}
{% endtabs %}

## StartGame

After players choose a game, you need to call the [startgame interface](/dev-docs/player-api/api-overview/api-v1-deprecated/game#start-a-game), passing in the game and scene IDs to start the game. In our Discord game, clicking the game button will fetch the game based on these IDs. In this interface, the API will return basic information about the game scene, background, NPC list, and initial dialogue.

In our Discord game, background information is displayed to help players understand the game. Relevant NPCs are loaded based on the NPC list for future conversations, and the initial dialogue between NPCs is automatically displayed.&#x20;

Through the initial dialogue, players can naturally learn about the NPC's character, style, and plot. The DM will also explain the current game goal.

<figure><img src="https://1241690067-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FChXuEllR7kvvuUM9K1Fi%2Fuploads%2FXiayphCFnCMreGFbQrnf%2Fbp-2.png?alt=media&amp;token=fa216fd2-1724-41e1-a501-591186db9418" alt=""><figcaption></figcaption></figure>

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

```bash
curl --location --request POST 'https://api.rpggo.ai/open/game/startgame' \
--header 'Application-ID: YOUR_RPGGO_APP_ID' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_RPGGO_API_KEY' \
--data '{ "session_id": "YOUR_SESSION_ID", "game_id": "6", "scene_id": "5", "continue": false }'
```

{% endtab %}
{% endtabs %}

## Chat

Once the game begins, you can use the [chat interface](/dev-docs/player-api/api-overview/api-v1-deprecated/npc#chat-with-npc-and-dm) at any time to engage in chat with the NPCs.&#x20;

<figure><img src="https://1241690067-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FChXuEllR7kvvuUM9K1Fi%2Fuploads%2FBaydbB8E8dniIJrCiLcQ%2Fbp-3.png?alt=media&amp;token=635958e1-f59f-4179-bac6-31b5a38d45d1" alt=""><figcaption></figcaption></figure>

To enhance the game's playability, each game round limits the number of conversations with NPCs. So, in the API's response, pay attention to the `"epoch"` field, as NPCs will stop responding after reaching the conversation limit.

<figure><img src="https://1241690067-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FChXuEllR7kvvuUM9K1Fi%2Fuploads%2FNdpg7qIo0B62zKxuQsYR%2Fbp-4.png?alt=media&amp;token=1cc6da03-dcfb-4369-b144-94f566c358b9" alt=""><figcaption></figcaption></figure>

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

```bash
curl --location --request POST 'https://api.rpggo.ai/open/game/chat' \
--header 'Application-ID: YOUR_RPGGO_APP_ID' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_RPGGO_API_KEY' \
--data '{ "session_id": "YOUR_SESSION_ID", "npc_id": "1144870688000327750", "message": "who are you?" }'
```

{% endtab %}
{% endtabs %}

The DM, as a special NPC, not only engages in regular chat but also controls the game's goals and game progression. The specific relationships between scenes, objectives, and NPCs can be found [here](/dev-docs/data-schema/understand-the-data-schema).

<figure><img src="https://1241690067-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FChXuEllR7kvvuUM9K1Fi%2Fuploads%2FrLjSeIzY3FoNw4z7pQpL%2Fbp-5.png?alt=media&amp;token=e33f6e0c-d28a-42a0-9a8e-5fba165656f9" alt=""><figcaption></figcaption></figure>

The game's progress status is indicated in the `"game status"` field of the API interface. You can start a new game or end the game based on this field.&#x20;

In our Discord game, when `"action=3"` (indicating the end of the game), a button to start a new game is automatically displayed, and relevant NPCs are removed. Of course, you can also implement a more interactive UI and save user game data to your server.

<figure><img src="https://1241690067-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FChXuEllR7kvvuUM9K1Fi%2Fuploads%2FQzGAM9n9mR68DkyvHv8R%2Fbp-6.png?alt=media&amp;token=056332f1-0d86-4fe4-9e5e-6bf492465496" alt=""><figcaption></figcaption></figure>

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

```sh
curl --location --request POST 'https://api.rpggo.ai/open/game/chat' \
--header 'Application-ID: YOUR_RPGGO_APP_ID' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_RPGGO_API_KEY' \
--data '{ "session_id": "YOUR_SESSION_ID", "npc_id": "1144871194668040232", "message": "James is the murderer" }'
```

{% endtab %}
{% endtabs %}


# Simple Chat Game with V2 API

Based on our V2 API, here is a 3rd party practice to demonstrate how to create a simple interactive website.

{% hint style="info" %}
Before diving into this document, it is strongly recommended to read [here](/dev-docs/data-schema/understand-the-data-schema) to understand the relationships between games, scenes, goals, DMs, and NPCs.
{% endhint %}

> All interfaces require the application of an app ID and authentication. The specific process can be found [here](/dev-docs/support/apply-your-test-key)

Check out the implementation code here: <https://github.com/codingtmd/simple-chat-game/>. \
\
![](https://1241690067-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FChXuEllR7kvvuUM9K1Fi%2Fuploads%2FfXioI4VpTqxGtZrboVKp%2FScreenshot%202024-10-02%20145148.png?alt=media\&token=ddfe80d2-341d-4348-9654-dbaa9a180f8d)


# 2D AI Town with V2 API

Based on our V2 API, here is a sample practice to demonstrate how to create an AI town in 2D. And you can build your own AI town if you wish.

{% hint style="info" %}
Before diving into this document, it is strongly recommended to read [here](/dev-docs/data-schema/understand-the-data-schema) to understand the relationships between games, scenes, goals, DMs, and NPCs.
{% endhint %}

> All interfaces require the application of an app ID and authentication. The specific process can be found [here](/dev-docs/support/apply-your-test-key)

Check out the implementation code here: <https://github.com/codingtmd/gamify-ai-town>. <br>

<br>

<figure><img src="https://1241690067-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FChXuEllR7kvvuUM9K1Fi%2Fuploads%2FjkVnKEu4IA0qeNfSxcfF%2FScreenshot%202024-10-20%20173451.png?alt=media&amp;token=90e8471b-1825-49c4-ab82-0d5c0f0dacf5" alt=""><figcaption></figcaption></figure>


# Stardew Valley Mod with V2 API

Instead of creating a game by yourself, you can also to be a Mod developer and ingest your favor game /character into any existing AAA game.

{% hint style="info" %}
Before diving into this document, it is strongly recommended to read [here](/dev-docs/data-schema/understand-the-data-schema) to understand the relationships between games, scenes, goals, DMs, and NPCs.
{% endhint %}

> All interfaces require the application of an app ID and authentication. The specific process can be found [here](/dev-docs/support/apply-your-test-key)

Check out the implementation code of Stardew Valley Mod here: <https://github.com/codingtmd/stardewAIRPG>\
\
And take a look of the game experience which combines RPGGO and Stardew Valley.<br>

{% embed url="<https://youtu.be/zE0sovb_f4U>" %}


# AI Game Website with V2 API

If you want to have you own ai game website, this open source code is just for you!

{% hint style="info" %}
Before diving into this document, it is strongly recommended to read [here](/dev-docs/data-schema/understand-the-data-schema) to understand the relationships between games, scenes, goals, DMs, and NPCs.
{% endhint %}

> All interfaces require the application of an app ID and authentication. The specific process can be found [here](/dev-docs/support/apply-your-test-key)

Check out the implementation code of Stardew Valley Mod here:&#x20;

<https://github.com/RPGGO-AI/singularity>\
\
And take a look of the game experience which combines RPGGO and Stardew Valley.<br>

{% embed url="<https://www.youtube.com/watch?v=_f0iuZsjHso>" %}


# Thesis 2024: A Text-to-Game Engine for UGC-Based Role-Playing Games

We are a startup working on AI-powered game engine. Here are what we learned in the past one year.

## <https://arxiv.org/abs/2407.08195> <a href="#one-sentence" id="one-sentence"></a>

{% embed url="<https://arxiv.org/pdf/2407.08195>" %}


# Initial Vision 2023: Text-To-OpenWorld Engine

We are a startup working on AI-powered game engine. Here are what you can expect in a long-term from RPGGO.

## One-sentence <a href="#one-sentence" id="one-sentence"></a>

As a technology firm, we are leveraging generative AI to build the next generation text-to-openworld engine, enabling players to live an adventure with a new form of online interactive experiences.

## Text to Open World <a href="#text-to-open-world" id="text-to-open-world"></a>

Existing open-world products are abundant, whether they are metaverse social products or pixelated games like Roblox. However, these products face a challenge: they struggle to evolve into universal UGC (User-Generated Content) platforms. This is because their world guide book and asset styles are official, but not open, diverse, or conducive to UGC, limiting them to vertical user bases. While these bases are highly engaged, this engagement doesn’t easily generalize across different user groups. The advent of generative AI offers a viable solution to these traditional shortcomings in open-world games. It fills the gaps in world-building and creative freedom for assets.

From a functional standpoint, generative AI brings transformative features:

* Text to Story: Real-time logical reasoning for text generation allows AI to create world guide books.
* Text to Assets: Real-time graphic rendering translates text into visuals, personalized according to user-defined styles, scenes, and elements. While 3D generation still has a long way to go, 2D is already feasible.

Behind these features, the most significant change may be in the production relationships,

> ***shifting creative threshold downward.***
>
> *This enables an open world based on UGC, personalized construction, and decentralized governance.*

Looking ahead to the next generation of open worlds, without getting into implementation details, they should at least include the following elements:

* World Guide Book, including storylines, characters, world objectives, and core conflicts.
* Personalized NPCs, including customized voices, behaviors, language styles, appearances, and clothing.
* Visual Rendering, including 2D and 3D forms of characters, scenes, props, and materials.
* Consumer-Level AI Infrastructure, reducing the daily cost per user to under $1 for scalability.
* Decentralized Finance, including payments, asset trading, and financial systems.

These elements #1， #2， #3， #4 form the basic building blocks of Text-to-Open World.

<figure><img src="https://1241690067-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FChXuEllR7kvvuUM9K1Fi%2Fuploads%2Fa3OrlnyYTjgmQEe0eL7o%2F2.png?alt=media&amp;token=1f33ec17-d55d-4963-a010-62a9a53b7c74" alt=""><figcaption></figcaption></figure>

So, what’s different in user behavior and consumer mindset in this new generation of open worlds?

* Imagine a game experience tailored just for you, where the entire world unfolds before you, and your actions in the game influence the storyline in real-time, NPCs remember your choices and react accordingly
* Assets are customized to your imagination, not limited by official constraints. The assets you create can be traded or sold, not just within one game but across an entire universe of interconnected experiences.
* The gaming experience is infinite and non-repetitive, with AI balancing individual and collective harmonization.
* The game itself becomes consumable UGC content, shareable and open to secondary creations.
* Immersive integration and autonomous NPC dialogues transport you into a ‘Ready Player One’ type of alternate world for chatting and interaction.”

This is the future we envision, a future where the lines between gaming, social interaction, and content creation are blurred, thanks to the power and potential of generative AI.

In this new paradigm, the game is not just a game; it’s a living, breathing ecosystem. It’s a platform for creativity, social interaction, and even economic activity. We’re not just talking about a technological shift; We believe it is a cultural revolution.

## What we are trying to do <a href="#what-we-are-trying-to-do" id="what-we-are-trying-to-do"></a>

In our startup, we aim to address these gaps by leveraging advanced generative AI to build the next Text-To-OpenWorld Engine and power the ability of UGC to create and play in his/her open world. We believe that the future of gaming and interactive products lies in the seamless integration of generative AI, and we’re excited to lead the way.

<figure><img src="https://1241690067-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FChXuEllR7kvvuUM9K1Fi%2Fuploads%2FJD6w4BQ6m3mhNmxvMsUB%2Fzagii.png?alt=media&amp;token=dbb4f454-1a9f-4731-a6f4-a5e743fbc612" alt=""><figcaption></figcaption></figure>

For the Zagii engine, the core features include but are not limited to:

* Fine-tuning based on open-source models with annotated RPG data to teach the AI how to create RPG games.
* Multi-LLM-model ensemble architecture, or what we call ‘llm-augmented autonomous agents architecture.’ Different large models take on different tasks and roles based on their unique capabilities during the generation process.
* RAG (Retrieval Augmented Generation), which utilizes a search framework to employ an external knowledge graph and meta-documents as search index, building prompts by adding the relevant retrieved data in context.
* Fast visual rendering: customized stable diffusion needs to generate an image within 2 seconds. \*Among these, the annotation of RPG data and fine-tuning of open-source models will require significant resource and computational power investments.

This is the technological foundation we’re laying, and it’s not just ambitious; it’s feasible. We’re not just dreaming big; we’re executing a scalable plan to make those dreams a reality. Achieving the ultimate form all at once is unrealistic. There will be an iterative path. We will start by supporting the creation of one-dimensional, small-scale open worlds—specifically, ‘murder mystery’ scenarios—as a stepping stone to gradually build our AI-OpenWorld capabilities.

But please note that we are NOT building one RPG game, but building an AI-Engine to generate RPG games, to generate mini-worlds.

## Creation Tooling

We will also release simple production tools that allow creators to quickly customize their story worlds and share them with friends, making your world easily shareable and initialized. Access [Creator Tool](https://developer.rpggo.ai/rpggo-creator-tutorial/) to start build your world and game.

<figure><img src="https://1241690067-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FChXuEllR7kvvuUM9K1Fi%2Fuploads%2FY6qhJ3HF15fiErtLfOAJ%2Fwhiteboard_exported_image.png?alt=media&amp;token=397ceacf-450f-435a-8970-c4741600dc69" alt=""><figcaption><p><a href="https://creator.rpggo.ai/">Creator Tool</a></p></figcaption></figure>

## Ecosystem

In order to better utilize the AI Engine capability with 3rd party partners, we open the public API to selected partners for real-time game scenarios rendering.

And, **Welcome to the Public API!** 😼🙀😻

## What's in the API <a href="#at-the-end" id="at-the-end"></a>

{% content-ref url="/pages/Tq5JEcq3NKI0PJNZ41FH" %}
[Getting Started](/dev-docs/introduction/getting-started)
{% endcontent-ref %}

{% content-ref url="/pages/dL7k17j7dhYj8tXwpzmj" %}
[Player API](/dev-docs/player-api/api-overview)
{% endcontent-ref %}


# Apply Your Test Key

What you need to make your game link into RPGGO's API...

* RPGGO Public API is in currently under **alpha phase** and do not open to auto-public application.&#x20;
* If you want to try it for personal demo, following below instruction to self-service your API key, but those of keys have rate limit.&#x20;
* If you need a key for a commercial use case(without rate limit), please submit an application form via [here](https://forms.gle/sw9kqPQNfBDcnya6A), or send an email to <mark style="background-color:yellow;"><dev@rpggo.ai></mark> to get an prod API key

### Get your API key

Your API requests are authenticated using API keys. Any request that doesn't include an API key will return an error.

The good news is, we are currently openning the api key management for everyone. You can

1. go to <https://rpggo.ai/>
2. Log in with your Google or Discord account. Click your avatar in the up-right corner and find the "Manage Your API Key" in the submenu. Copy the API key.

<figure><img src="https://1241690067-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FChXuEllR7kvvuUM9K1Fi%2Fuploads%2FgcIdtcKeILKGh10InfOq%2Fscreenshot-20241219-083436.png?alt=media&amp;token=14618069-7262-430f-93b1-d8f574d6fa6f" alt=""><figcaption></figcaption></figure>

### Use API key to authenticate

For users who create multiple apps, you should pass a header to specify which App is used for an API request. Future usage from these API requests will count against the specified App's subscription quota.

{% hint style="info" %}
**Remember that your API key is a secret!**  Do not share it with others or expose it in any client-side code (browsers, apps). Production requests must be routed through your own backend server where your API key can be securely loaded from an environment variable or key management service.
{% endhint %}

All API requests should include API key in  HTTP header as follows:

```
Authorization: Bearer YOUR_RPGGO_API_KEY
```

Example curl command:

```bash
curl https://api.rpggo.ai/open/game/gamelist \
  -H "Authorization: Bearer $YOUR_RPGGO_API_KEY" 
```

RPGGO server will verify permissions by the **`Authorization`** and several other parameters. If an incorrect key is used the API will return a 401 HTTP error.


# Contact us

With this doc, we aim to instill a sense of urgency and excitement about the groundbreaking work we’re doing. We’re not just another startup; we’re a revolution waiting to happen, and this is the chance to be part of it.

Feel free to contact us at **<dev@rpggo.ai>** for any suggestions and API feedbacks.


