跳转至

启动指定的 space

POST /api/v5/spaces/{owner}/{repo_name}/start

启动指定的 space:服务端会按 owner / repo_name 解析出项目,随后重新拉取代码并部署运行该 space。

访问令牌支持说明

  • AtomGit 用户访问令牌(AtomGit user access tokens)

是否允许匿名访问

此接口不允许匿名访问

请求参数

参数名 位置 类型 必填 说明
owner path string 是 仓库所属空间地址(企业、组织或个人的地址path)
repo_name path string 是 仓库路径(path)
access_token query string 是 用户授权码

Request Body:

启动 space 所需的镜像、服务器规格与运行时长,三个字段均必填。

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "image_id": {
      "description": "镜像ID",
      "type": "string",
      "minLength": 32,
      "maxLength": 32,
      "example": "swr.cn-south-1.myhuaweicloud.com/atomgit-ai/online-ubuntu22-py311-torch2.8-gradio6.9:v1.0.0"
    },
    "server_id": {
      "description": "服务器规格ID",
      "type": "string",
      "example": "xrtf1hp5jebv32k6zm9o0unlq74g8777"
    },
    "duration_time": {
      "description": "持续时间(秒),到期休眠",
      "type": "number"
    }
  },
  "required": ["image_id", "server_id", "duration_time"]
}

Note: image_id / server_id 可通过「查询 space 可用的基础镜像列表」与「查询 space 可用的硬件配置列表」获取。

响应参数

该接口成功时返回空响应体(HTTP 200),不返回业务数据。

失败响应

400 参数错误

{
  "error_code_name": "BAD_REQUEST",
  "code": 400,
  "error_message": "镜像不能为空!"
}

401 未认证

{
  "error_code_name": "UNAUTHORIZED",
  "code": 401,
  "error_message": "Unauthorized"
}

403 无权限

{
  "error_code_name": "FORBIDDEN",
  "code": 403,
  "error_message": "Forbidden"
}

HTTP 响应状态码

状态码 说明
200 成功(OK)
400 参数错误或项目不存在(Bad Request)
401 需要认证(Unauthorized)
403 禁止访问(Forbidden)
500 系统内部错误(Internal Server Error)

请求示例

参数说明

<owner> 替换为仓库所属空间地址(企业、组织或个人的地址 path) 如果是三段命名空间,例如: gh_mirrors/co/QwenPaw。owner值为gh_mirrors/co,调用时必须把第一个 / 编码为 %2F,owner传值为: gh_mirrors%2Fco。

<repo_name> 替换为仓库路径;

<token> 替换为你的 AtomGit 用户访问令牌;

<image_id> 替换为镜像 ID(32 位);

<server_id> 替换为服务器规格 ID;

<duration_time> 替换为期望的运行时长(秒)。

cURL

curl -X POST 'https://api.atomgit.com/api/v5/spaces/<owner>/<repo_name>/start?access_token=<token>' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d '{
    "image_id": "<image_id>",
    "server_id": "<server_id>",
    "duration_time": 3600
  }'

JavaScript

// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch(
  "https://api.atomgit.com/api/v5/spaces/<owner>/<repo_name>/start?access_token=<YOUR-TOKEN>",
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Accept": "application/json",
    },
    body: JSON.stringify({
      image_id: "<image_id>",
      server_id: "<server_id>",
      duration_time: 3600,
    }),
  }
);

if (!response.ok) {
  throw new Error(`请求失败: ${response.status}`);
}

Python

import requests

resp = requests.post(
    "https://api.atomgit.com/api/v5/spaces/<owner>/<repo_name>/start",
    params={"access_token": "<YOUR-TOKEN>"},
    json={
        "image_id": "<image_id>",
        "server_id": "<server_id>",
        "duration_time": 3600,
    },
    headers={"Accept": "application/json"},
    timeout=10,
)
resp.raise_for_status()

响应示例

状态码: 200

{}

错误码

错误码 说明
400 参数错误(如缺少 image_id / server_id / duration_time)、项目不存在
401 未认证或凭证无效(缺少/无效的访问令牌)
403 无权限操作该 space
404 请求路径不存在
405 请求方法不支持
429 请求过于频繁,触发限流
500 系统内部错误

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc