---
title: "创建虚拟机"
method: POST
path: "/api/v1/users/hosts/vms"
tags: ["【用户】主机管理"]
---

# 创建虚拟机

`POST /api/v1/users/hosts/vms`

创建虚拟机

## Request body

- DomainCreateVMReq
  - `git_identity_id` string
  - `host_id` string, required
  - `image_id` string, required
  - `install_coding_agents` boolean
  - `life` integer
  - `model_id` string, required
  - `name` string, required
  - `repo` DomainTaskRepoReq
    - `branch` string
    - `repo_filename` string
    - `repo_url` string
    - `zip_url` string
  - `resource` DomainResource, required
    - `cpu` integer
    - `memory` integer

## Response `200`

成功

- object
  - `code` integer
  - `data` DomainVirtualMachine
    - `conditions` GithubComChaitinMonkeyCodeBackendEntTypesCondition[]
      - `last_transition_time` integer
      - `message` string
      - `progress` integer
      - `reason` string
      - `status` 0 | 1 | 2 | 3
      - `type` 'Scheduled' | 'ImagePulled' | 'ProjectCloned' | 'ImageBuilt' | 'ContainerCreated' | 'ContainerStarted' | 'Ready' | 'Failed' | 'Hibernated'
    - `cores` integer
    - `created_at` integer
    - `environment_id` string
    - `host` DomainHost
      - `arch` string
      - `cores` integer
      - `default` boolean
      - `external_ip` string
      - `groups` DomainTeamGroup[]
        - `created_at` integer
        - `id` string
        - `name` string
        - `updated_at` integer
        - `users` DomainUser[]
          - `avatar_url` string
          - `email` string
          - `has_password` boolean
          - `id` string
          - `identities` DomainUserIdentity[]
            - `avatar_url` string
            - `email` string
            - `id` string
            - `identity_id` string
            - `platform` 'baizhi' | 'google' | 'github' | 'gitlab' | 'gitea' | 'gitee' | 'oidc'
            - `username` string
          - `is_blocked` boolean
          - `name` string
          - `role` 'individual' | 'enterprise' | 'subaccount' | 'admin' | 'gittask'
          - `status` 'active' | 'inactive' | 'banded'
          - `team` DomainTeam
            - `id` string
            - `name` string
          - `token` string
          - `wechat_mp_bound` boolean
      - `id` string
      - `is_default` boolean
      - `memory` integer
      - `name` string
      - `os` string
      - `owner` DomainOwner
        - `id` string
        - `name` string
        - `type` 'private' | 'public' | 'team'
      - `remark` string
      - `status` 'online' | 'offline'
      - `version` string
      - `virtualmachines` DomainVirtualMachine[]
      - `weight` integer
    - `hostname` string
    - `id` string
    - `life_time_seconds` integer
    - `memory` integer
    - `name` string
    - `os` string
    - `owner` DomainUser
      - `avatar_url` string
      - `email` string
      - `has_password` boolean
      - `id` string
      - `identities` DomainUserIdentity[]
        - `avatar_url` string
        - `email` string
        - `id` string
        - `identity_id` string
        - `platform` 'baizhi' | 'google' | 'github' | 'gitlab' | 'gitea' | 'gitee' | 'oidc'
        - `username` string
      - `is_blocked` boolean
      - `name` string
      - `role` 'individual' | 'enterprise' | 'subaccount' | 'admin' | 'gittask'
      - `status` 'active' | 'inactive' | 'banded'
      - `team` DomainTeam
        - `id` string
        - `name` string
      - `token` string
      - `wechat_mp_bound` boolean
    - `ports` DomainVMPort[]
      - `error_message` string
      - `forward_id` string
      - `port` integer
      - `preview_url` string
      - `status` 'reserved' | 'connected'
      - `success` boolean
      - `white_list` string[]
    - `status` 'unknown' | 'pending' | 'online' | 'offline' | 'hibernated'
    - `version` string
  - `message` string

## Other responses

- `400` — 请求参数错误
- `401` — 未授权
- `500` — 服务器错误

---

[API](https://skmtc.net/chaitin/apis/untitled-api.md) · [All operations](https://skmtc.net/chaitin/apis/untitled-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/chaitin/untitled-api/versions/5a5929cb17f2/schema)
