Choose how to use Kimi Hosted Agents
Prerequisites
- Sign up for a Kimi API Platform account.
- When using the kha CLI or cURL, create an API key under Organization - API Keys.
- When using the Console, no API key is needed—simply sign in to your account.
Core concepts
Each of these concepts has a dedicated management page in the Console; see Using the Console.
Recommended: Use the kha CLI
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: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 The list includes the official agent PPT Assistant, which comes preconfigured with financial plugins and presentation skills. Save its
jq installed, filter the output to show only each agent’s name and id:id:2
Create an execution environment
Create an execution environment for generating presentations. Save the environment ID (
config is required; {"type": "cloud"} creates a cloud execution environment using default values for all other settings:id field) from the response: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 thecursorquery parameter orLast-Event-IDrequest header when reconnecting to resume from where you left off.event: Event type, matching thetypefield in the event JSON.data: Single-line event JSON containing the event ID (idfield with thesevt_prefix),processed_at,type, and thedatapayload.
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 Download the artifact:Once the download finishes, open
session.status event arrives in the stream with status set to "idle" in data, the current turn is complete.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: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 Replace
prefix as a path relative to the session filesystem root (for example, output refers to output/ under the root):<PATH> with the file entry’s path field to download the file:Notes
-
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. - 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.