Skip to main content

Documentation Index

Fetch the complete documentation index at: https://asterai.io/docs/llms.txt

Use this file to discover all available pages before exploring further.

This guide walks you through creating your first asterai component and running it in an environment.

๐Ÿ“‹ Prerequisites

Overview

Youโ€™ll create a simple component that exports a greeting function, then run it locally in an environment.

Steps

1. Install the CLI

npm install -g @asterai/cli

2. Authenticate

Generate an API key from the console:
asterai auth login <your_api_key>
Verify youโ€™re logged in:
asterai auth status

3. Create a new component

asterai component init hello-world
cd hello-world
This scaffolds a TypeScript component project with the following structure:
hello-world/
  component.ts       # Component implementation
  component.wit      # WIT interface definition
  package.json       # Build scripts and dependencies
  tsconfig.json
  .gitignore

4. Understanding the interface

The scaffolded component.wit defines a simple interface. If youโ€™re logged in, the CLI automatically sets your username as the namespace:
package your-username:hello-world@0.1.0;

interface hello-world {
  greet: func(name: string);
}

world component {
  import asterai:host/api@1.0.0;

  export hello-world;
}
This declares a component that exports one function: greet, which takes a name and prints a greeting.

5. Understanding the implementation

The scaffolded component.ts implements the interface:
import * as host from "asterai:host/api@1.0.0";

const greet = (name: string) => {
  console.log(`hello ${name}!`);
};

export const helloWorld = {
  greet
};
The exported object name matches the interface name in component.wit (kebab-case hello-world becomes camelCase helloWorld in TypeScript).

6. Install dependencies and build

npm install
asterai component build

7. Push the component

Push your component to the registry:
asterai component push

8. Create an environment

Create a new environment and add your component to it:
asterai env init my-env
asterai env add-component my-env your-username:hello-world@0.1.0

9. Call your function

Call your componentโ€™s function:
asterai env call my-env your-username:hello-world hello-world.greet '"World"'
You should see: hello World! ๐ŸŽ‰

10. Push to the cloud (optional)

To run your environment in the cloud, push it to the registry:
asterai env push my-env
Your environment is now available to run on asteraiโ€™s cloud infrastructure.

๐ŸŽฏ Whatโ€™s Next?

Youโ€™ve created a component and run it in an environment. From here you can:
  • โž• Add more functions to your component
  • ๐Ÿ“ฅ Import other components from the registry
  • ๐Ÿ”ง Add configuration (environment variables, secrets) to your environment
  • ๐Ÿ”— Compose multiple components in a single environment
See the Components page for more on building components, or Registry for publishing and discovering components.