# Bonsai Client

The Bonsai Client is essentially an Express server that enables the creation, updating, and management of Smart Media posts.&#x20;

Developers simply have to create a new template file and let the client handle the rest.

### Core Functionality

* Register the supported templates and their handler functions
* Create and manage smart media posts
* Generate previews before post creation
* Update posts content on-demand or as part of a cron job

### Smart Media Templates

This concept is borrowed from ElizaOS actions, which provided agents discrete functionality based on user input.&#x20;

Smart Media Templates define a type of dynamic post, whether it be a choose-your-own-adventure, evolving art, or simulated reality.&#x20;

The template defines the necessary context, memory, and logic that a post will need in order to infinitely update. This essentially turns the post into a state machine, always producing new post metadata for a Lens post.

Read more about the structure of templates, with two examples:

{% content-ref url="templates" %}
[templates](https://onbonsai.gitbook.io/docs/smart-media/building-smart-media/templates)
{% endcontent-ref %}

### Workflow

Our platform enables the entire creation workflow for users, leaving developers to focus on building new and exciting smart media templates. What does the user experience look like when creating a smart media post?

* The user starts by picking from the available templates (ie: **adventure time, evolving art**)
* The user configures the media - whatever the template requires (ie: the prompt, style)
* The ElizaOS server will potentially generate a preview of the smart media
* The user will publish the post, which sets the necessary metadata on the Lens api and registers the `postId` with our server
* Post Updates: The developer will trigger updates to the post content - on-demand or through a cron job. This potentially generates new metadata and refreshes the post on Lens

### User API Credits

The Bonsai Client ships with a user credit tracking system. This limits the amount of external API calls (post updates, messages) that a specific user can make on a daily basis by tracking their usage in a database. One credit equals one cent worth of external API usage. The system includes estimates for how much an execution should cost and checks that a user has enough credits before their post gets updated or message response is generated and decrements the credits afterwards.

The credit tracking system can be disabled entirely by setting `DISABLE_CREDITS=true` in the `.env` .

### API Endpoints

This is just a summary of the endpoints exposed by the client. These will likely change as the client matures and we get more complex smart media templates.

* **POST /post/create-preview:** Generates a preview for a new smart media post before creation
* **POST /post/create:** Creates a new smart media post after the Lens post has been created
* **GET /post/:postId:** Retrieves the latest URI and metadata for a smart media post
* **POST /post/:postId/update:** Triggers an update process for a smart media post
