Skip to main content

Choose how to use Kimi Hosted Agents

Prerequisites

Core concepts

Each of these concepts has a dedicated management page in the Console; see Using the Console. We recommend using the kha CLI to complete your first task. Once installed and authenticated, you can create and configure agents, submit and continue tasks, inspect run status, and download artifacts in natural language from AI coding assistants such as Kimi Code, Claude Code, or Codex—without writing API requests by hand. On macOS or Linux, install the kha CLI and log in:
The CLI installer is distributed globally from ha-static.moonshot.cn; to install from GitHub Releases instead, set KHA_RELEASE_BASE_URL=https://github.com/MoonshotAI/kha/releases/download and pin a version with KHA_VERSION=0.X.Y. The --base-url https://api.moonshot.ai flag connects the CLI to the Global API endpoint (the CLI defaults to the CN endpoint if omitted). When prompted (input is hidden), paste an API key created on Kimi API Platform and press Enter. For multi-account profiles and the companion kha skill package for AI coding assistants, see kha CLI.

Run your first task

The walkthrough below demonstrates the same presentation-generation task in two ways: calling the REST API with cURL, or using the kha CLI. Choose either approach—you do not need to run both. You will select an agent, prepare an execution environment, create a session, send a message, and download the generated artifact.
1

List and select an agent

List the available agents:
The response includes the full definition of every agent and can be quite long. If you have jq installed, filter the output to show only each agent’s name and id:
The list includes the official agent PPT Assistant, which comes preconfigured with financial plugins and presentation skills. Save its id:
2

Create an execution environment

Create an execution environment for generating presentations. config is required; {"type": "cloud"} creates a cloud execution environment using default values for all other settings:
Save the environment ID (id field) from the response:
The cloud sandbox image for a new execution environment builds asynchronously and typically becomes ready shortly after creation. If creating a session in the next step fails because the environment is not ready yet, wait a moment and try again.
3

Create a session

Create a session bound to the agent and execution environment saved earlier:
Save the session ID (id field) from the response:
4

Subscribe to the event stream

To receive the agent’s output in real time, open a second terminal and subscribe to the session’s SSE event stream before sending a message:
Each frame in the stream contains three lines—id, event, and data:
  • id: Resume cursor (not the event ID). Pass it back as the cursor query parameter or Last-Event-ID request header when reconnecting to resume from where you left off.
  • event: Event type, matching the type field in the event JSON.
  • data: Single-line event JSON containing the event ID (id field with the sevt_ prefix), processed_at, type, and the data payload.
Once you send a message, you will see event frames similar to the following in the stream:
The frames above are simplified examples illustrating the shape of the stream. For the full list of event types, see Event Stream.
5

Send a message

Return to your original terminal and send a message to the session to start the task:
After sending the message, the terminal subscribed to the event stream begins receiving execution events as the agent works through the task.
6

Wait for completion and download the artifact

When a session.status event arrives in the stream with status set to "idle" in data, the current turn is complete.
The event stream supports resuming after a disconnect: if the connection drops, include the Last-Event-ID header (set to the id of the last frame you received) when reconnecting to pick up where you left off without missing intermediate output. For reconnection details and error codes, see Event Stream and FAQ.
The presentation generated by the agent is registered as an artifact via the built-in save_artifact tool. List the session’s artifacts, locate the .pptx file, and save its id:
Download the artifact:
Once the download finishes, open output.pptx locally to view the generated presentation.
7

(Optional) Browse all files in the session

Artifacts include only files explicitly delivered by the agent. If you need intermediate files or the artifact list is empty, browse the session filesystem directly. The endpoint does not list subdirectories recursively—each call returns a single directory level. To enter a subdirectory, pass prefix as a path relative to the session filesystem root (for example, output refers to output/ under the root):
Replace <PATH> with the file entry’s path field to download the file:

Notes

  1. Hosted Agents is a stateful service: session history, sandbox state, and generated files persist on the server. You can delete sessions via the API after archiving them (which sets their status to terminated), and delete uploaded files individually.
  2. For pricing details, see Hosted Agents Pricing. For common errors and troubleshooting, see FAQ.

Next steps

Start your first task with kha CLI

Create and configure agents, submit and continue tasks, and download artifacts in natural language from an AI coding assistant.

Configure resources in the Console

Configure resources, monitor runs, and inspect artifacts in your browser.

Create and manage agents

Configure models, system prompts, tools, MCP servers, skills, and plugins.

Create and manage sessions

Create sessions, bind resources, and send your first message.

Inspect and handle real-time events

Subscribe to events, resume after disconnects, and handle errors.