> ## Documentation Index
> Fetch the complete documentation index at: https://platform.kimi.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Get started with Kimi Hosted Agents, a prebuilt, configurable hosted runtime for long-running and asynchronous agent tasks.

## Choose how to use Kimi Hosted Agents

| Method | Best for | Entry point |
| - | - | - |
| kha CLI (Recommended) | **Complete your first task in natural language** inside an AI coding assistant (such as [Kimi Code](https://platform.kimi.ai/docs/guide/kimi-code-cli.md)), then continue managing agents and sessions | [Use kha CLI](https://platform.kimi.ai/docs/hosted-agents/kha.md) |
| API | Integrate Hosted Agents into your own systems or call the API directly | [See the example below](#run-your-first-task) |
| Console | Configure resources, monitor runs, and inspect artifacts in your browser without writing code | [Use the Console](https://platform.kimi.ai/docs/hosted-agents/console.md) |

## Prerequisites

* Sign up for a [Kimi API Platform account](https://platform.kimi.ai/console).
* When using the kha CLI or cURL, create an API key under [Organization - API Keys](https://platform.kimi.ai/console/api-keys).
* When using the Console, no API key is needed—simply sign in to your account.

```bash theme={null}
export KIMI_API_KEY="your_kimi_api_key"
```

## Core concepts

| Concept | Description |
| - | - |
| **Agent** | Combines a model, system prompt, tools, MCP servers, skills, and plugins |
| **Skill** | A modular capability package that you can attach to an agent as needed to extend its domain knowledge or refine its workflows; available as both official and custom skills |
| **Plugin** | A reusable capability bundle combining MCP servers and skills; available as both official and custom plugins |
| **Session** | A single running instance of an agent that carries out tasks and produces outputs inside an execution environment |
| **Environment** | Cloud sandbox configuration for sessions, including preinstalled dependencies, network access policies, and setup scripts |
| **Vault** | Centralized storage for third-party service credentials, bound when creating a session |

Each of these concepts has a dedicated management page in the Console; see [Using the Console](https://platform.kimi.ai/docs/hosted-agents/console.md).

## 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](https://platform.kimi.ai/docs/guide/kimi-code-cli.md), Claude Code, or Codex—**without writing API requests by hand**.

On macOS or Linux, install the kha CLI and log in:

```bash theme={null}
curl -fsSL https://ha-static.moonshot.cn/kha/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
kha login --base-url https://api.moonshot.ai
```

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](https://platform.kimi.ai/console/api-keys) and press Enter. For multi-account profiles and the companion kha skill package for AI coding assistants, see [kha CLI](https://platform.kimi.ai/docs/hosted-agents/kha.md).

## 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:

```bash cURL theme={null}
curl -sS "https://api.moonshot.ai/v1/agents" \
  -H "Authorization: Bearer $KIMI_API_KEY" \
  -H "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha agents list
```

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`:

```bash cURL theme={null}
curl -sS "https://api.moonshot.ai/v1/agents" \
  -H "Authorization: Bearer $KIMI_API_KEY" \
  -H "kimi-api-version: 2026-09-01-beta" \
  | jq -r '.items[] | "name: \(.name)\tid: \(.id)"'
```

```bash CLI theme={null}
kha agents list -o json | jq -r '.items[] | "name: \(.name)\tid: \(.id)"'
```

The list includes the official agent **PPT Assistant**, which comes preconfigured with financial plugins and presentation skills. Save its `id`:

```bash theme={null}
export AGENT_ID="agent_..."
```

**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:

```bash cURL theme={null}
curl -sS -X POST "https://api.moonshot.ai/v1/environments" \
  -H "Authorization: Bearer $KIMI_API_KEY" \
  -H "kimi-api-version: 2026-09-01-beta" \
  -H "Content-Type: application/json" \
  -d @- <<'JSON'
{
  "name": "PPT Environment",
  "description": "Environment for generating and saving PPT files",
  "config": {
    "type": "cloud"
  }
}
JSON
```

```bash CLI theme={null}
kha environments create --name "PPT Environment" --description "Environment for generating and saving PPT files"
```

Save the environment ID (`id` field) from the response:

```bash theme={null}
export ENVIRONMENT_ID="env_..."
```

> [!TIP]
>
> 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:

```bash cURL theme={null}
curl -sS -X POST "https://api.moonshot.ai/v1/sessions" \
  -H "Authorization: Bearer $KIMI_API_KEY" \
  -H "kimi-api-version: 2026-09-01-beta" \
  -H "Content-Type: application/json" \
  -d @- <<JSON
{
  "agent_id": "$AGENT_ID",
  "environment_id": "$ENVIRONMENT_ID",
  "title": "Generate financial market analysis PPT"
}
JSON
```

```bash CLI theme={null}
kha sessions create --agent "$AGENT_ID" --environment "$ENVIRONMENT_ID" --title "Generate financial market analysis PPT"
```

Save the session ID (`id` field) from the response:

```bash theme={null}
export SESSION_ID="sesn_..."
```

**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:

```bash cURL theme={null}
curl -sS -N "https://api.moonshot.ai/v1/sessions/$SESSION_ID/events/stream" \
  -H "Authorization: Bearer $KIMI_API_KEY" \
  -H "kimi-api-version: 2026-09-01-beta" \
  -H "Accept: text/event-stream"
```

```bash CLI theme={null}
kha sessions attach "$SESSION_ID"
```

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:

```text theme={null}
id: 101
event: session.status
data: {"id":"sevt_01h455vb4pex5vsknk084sn02q","processed_at":"2026-09-01T08:00:01Z","type":"session.status","data":{"status":"running"}}

id: 102
event: agent.thinking
data: {"id":"sevt_01h455vb4pex5vsknk084sn02r","processed_at":"2026-09-01T08:00:03Z","type":"agent.thinking","data":{"content":[{"type":"thinking","thinking":"I need to search for financial sector market data from the past two days first..."}]}}

id: 103
event: agent.tool_use
data: {"id":"sevt_01h455vb4pex5vsknk084sn02s","processed_at":"2026-09-01T08:00:05Z","type":"agent.tool_use","data":{"tool_use":{"id":"call_1","name":"web_search","input":{"query":"financial sector stock market performance last 2 days"}},"evaluated_permission":"always_allow"}}

id: 104
event: agent.message
data: {"id":"sevt_01h455vb4pex5vsknk084sn02t","processed_at":"2026-09-01T08:00:20Z","type":"agent.message","data":{"content":[{"type":"text","text":"The presentation has been generated and saved in the output/ directory."}]}}
```

> [!NOTE]
>
> The frames above are simplified examples illustrating the shape of the stream. For the full list of event types, see [Event Stream](https://platform.kimi.ai/docs/hosted-agents/event-stream.md).

**5. Send a message**

Return to your original terminal and send a message to the session to start the task:

```bash cURL theme={null}
curl -sS -X POST "https://api.moonshot.ai/v1/sessions/$SESSION_ID/events" \
  -H "Authorization: Bearer $KIMI_API_KEY" \
  -H "kimi-api-version: 2026-09-01-beta" \
  -H "Content-Type: application/json" \
  -d @- <<'JSON'
{
  "events": [
    {
      "type": "user.message",
      "data": {
        "content": [
          {
            "type": "text",
            "text": "You are a financial equity researcher. Summarize financial sector stock performance over the past two days and generate a morning briefing PPT."
          }
        ]
      }
    }
  ]
}
JSON
```

```bash CLI theme={null}
kha sessions send "$SESSION_ID" "You are a financial equity researcher. Summarize financial sector stock performance over the past two days and generate a morning briefing PPT."
```

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.

> [!TIP]
>
> 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](https://platform.kimi.ai/docs/hosted-agents/event-stream.md) and [FAQ](https://platform.kimi.ai/docs/hosted-agents/faq.md).

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`:

```bash cURL theme={null}
curl -sS "https://api.moonshot.ai/v1/artifacts?session_id=$SESSION_ID" \
  -H "Authorization: Bearer $KIMI_API_KEY" \
  -H "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha artifacts list --session "$SESSION_ID"
```

Download the artifact:

```bash cURL theme={null}
export ARTIFACT_ID="arti_..."
curl -sS -o output.pptx "https://api.moonshot.ai/v1/artifacts/$ARTIFACT_ID/content" \
  -H "Authorization: Bearer $KIMI_API_KEY" \
  -H "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
export ARTIFACT_ID="arti_..."
kha artifacts download "$ARTIFACT_ID" --out output.pptx
```

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):

```bash cURL theme={null}
curl -sS "https://api.moonshot.ai/v1/sessions/$SESSION_ID/filesystem" \
  -H "Authorization: Bearer $KIMI_API_KEY" \
  -H "kimi-api-version: 2026-09-01-beta"
curl -sS "https://api.moonshot.ai/v1/sessions/$SESSION_ID/filesystem?prefix=output" \
  -H "Authorization: Bearer $KIMI_API_KEY" \
  -H "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha sessions fs list "$SESSION_ID"
kha sessions fs list "$SESSION_ID" --prefix output
```

Replace `<PATH>` with the file entry's `path` field to download the file:

```bash cURL theme={null}
curl -sS -o <LOCAL_FILE> "https://api.moonshot.ai/v1/sessions/$SESSION_ID/filesystem/raw?path=<PATH>" \
  -H "Authorization: Bearer $KIMI_API_KEY" \
  -H "kimi-api-version: 2026-09-01-beta"
```

```bash CLI theme={null}
kha sessions fs download "$SESSION_ID" "<PATH>" --out <LOCAL_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](https://platform.kimi.ai/docs/pricing/hosted-agents.md). For common errors and troubleshooting, see [FAQ](https://platform.kimi.ai/docs/hosted-agents/faq.md).

## Next steps

> [card] [Start your first task with kha CLI](https://platform.kimi.ai/docs/hosted-agents/kha.md)
>
> Create and configure agents, submit and continue tasks, and download artifacts in natural language from an AI coding assistant.

> [card] [Configure resources in the Console](https://platform.kimi.ai/docs/hosted-agents/console.md)
>
> Configure resources, monitor runs, and inspect artifacts in your browser.

> [card] [Create and manage agents](https://platform.kimi.ai/docs/hosted-agents/agents.md)
>
> Configure models, system prompts, tools, MCP servers, skills, and plugins.

> [card] [Create and manage sessions](https://platform.kimi.ai/docs/hosted-agents/sessions.md)
>
> Create sessions, bind resources, and send your first message.

> [card] [Inspect and handle real-time events](https://platform.kimi.ai/docs/hosted-agents/event-stream.md)
>
> Subscribe to events, resume after disconnects, and handle errors.
