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

# 快速入门：Enterprise

> 作为具备 RBAC 和多组织支持的企业用户开始使用 Devin API

本指南将引导你为具备自定义角色、RBAC 和多组织支持的 **企业组织** 配置 API 访问权限。

<Note>
  如果你使用的是仅包含单个组织且不需要自定义角色的团队版方案，可以参考更简单的 [Teams 快速入门](/zh/api-reference/getting-started/teams-quickstart)。
</Note>

<Note>
  如果你是拥有专用部署的 **Devin Enterprise** 客户，你需要将所有 API URL 中的 `api.devin.ai` 替换为你组织的自定义 API 域名 (例如，`api.your-company.devinenterprise.com`) 。如果你不确定贵组织的 API 域名，请联系你的 Devin 管理员或 Cognition 支持团队。
</Note>

<div id="understanding-service-user-scopes">
  ## 了解服务用户作用域
</div>

Enterprise 客户可以在两个层级创建服务用户：

| 作用域              | 基础 URL                         | 使用场景                             |
| ---------------- | ------------------------------ | -------------------------------- |
| **Enterprise**   | `/v3/enterprise/*`             | 跨组织管理、分析、审计日志、成员管理               |
| **Organization** | `/v3/organizations/{org_id}/*` | 单个组织内的会话、Knowledge、playbook、机密信息 |

具有 Enterprise 级权限的服务用户会在**所有**组织中自动继承相应的组织级权限。

<div id="step-1-create-a-service-user">
  ## 步骤 1：创建服务用户
</div>

<div id="enterprise-service-user-cross-org-access">
  ### Enterprise 服务用户 (跨组织访问)
</div>

1. 前往 **Enterprise settings > Service users**
2. 点击 **Create service user**
3. 选择一个名称 (例如：“Analytics Dashboard”、“Org Provisioning Bot”)
4. 为其分配一个 Enterprise 角色，使其具备集成所需的权限

<div id="organization-service-user-single-org-access">
  ### 组织服务用户 (单组织访问)
</div>

1. 在目标组织中进入 **Settings > Service users**
2. 点击 **Create service user**
3. 选择名称并分配组织级角色

<Tip>
  遵循**最小权限原则**：当你的集成只需要访问一个组织时，创建以该组织为作用域的服务用户。仅在需要跨组织的工作流时使用 Enterprise 服务用户。
</Tip>

<div id="step-2-generate-an-api-key">
  ## 步骤 2：生成 API key
</div>

1. 创建服务账户后，点击 **Generate API key** 按钮
2. 立即复制该 API key——它以 `cog_` 开头，且不会再次显示
3. 将其安全保存为环境变量：

```bash theme={null}
export DEVIN_API_KEY="cog_your_key_here"
```

<div id="step-3-make-your-first-api-call">
  ## 第 3 步：发起第一次 API 调用
</div>

<div id="enterprise-endpoint-example">
  ### Enterprise 端点示例
</div>

列出你 Enterprise 帐户中的所有组织：

```bash theme={null}
curl "https://api.devin.ai/v3/enterprise/organizations" \
  -H "Authorization: Bearer $DEVIN_API_KEY"
```

<div id="organization-endpoint-example">
  ### 组织端点示例
</div>

在指定组织中创建 Devin 会话：

```bash theme={null}
export DEVIN_ORG_ID="your_org_id"

curl -X POST "https://api.devin.ai/v3/organizations/$DEVIN_ORG_ID/sessions" \
  -H "Authorization: Bearer $DEVIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Implement the feature described in JIRA-123"}'
```

<div id="permissions-and-rbac">
  ## 权限与 RBAC
</div>

每个 API 端点都受特定权限控制。每个端点所需的权限都记录在该端点的 API 参考页面中。权限分为两个层级：

* **Enterprise 权限** — 控制 `/v3/enterprise/*` 端点 (例如 `ManageOrganizations`、`ManageBilling`、`ViewAccountMetrics`)
* **组织权限** — 控制 `/v3/organizations/{org_id}/*` 端点 (例如 `UseDevinSessions`、`ManageOrgSecrets`、`ManageOrgPlaybooks`)

拥有 Enterprise 级权限的 Enterprise 服务用户，会自动在所有组织中继承相应的组织级权限。例如，`ViewAccountSessions` 会在每个组织中授予 `ViewOrgSessions`。

完整的权限参考请参阅[权限与 RBAC 文档](/zh/api-reference/v3/overview#enterprise-permissions)。

<div id="common-enterprise-workflows">
  ## 常见企业级工作流程
</div>

<div id="monitor-consumption-across-orgs">
  ### 跨组织监控用量
</div>

```bash theme={null}
# 获取每日消耗明细（使用 Unix 时间戳 — 示例：2025 年 1 月 1 日至 1 月 31 日）
curl "https://api.devin.ai/v3/enterprise/consumption/daily?time_after=1735689600&time_before=1738368000" \
  -H "Authorization: Bearer $DEVIN_API_KEY"
```

<div id="audit-log-retrieval">
  ### 审计日志检索
</div>

```bash theme={null}
curl "https://api.devin.ai/v3/enterprise/audit-logs" \
  -H "Authorization: Bearer $DEVIN_API_KEY"
```

<div id="manage-users-across-organizations">
  ### 跨组织管理用户
</div>

```bash theme={null}
# 列出企业用户
curl "https://api.devin.ai/v3/enterprise/members/users" \
  -H "Authorization: Bearer $DEVIN_API_KEY"

# 列出特定组织中的用户
curl "https://api.devin.ai/v3/enterprise/organizations/$DEVIN_ORG_ID/members/users" \
  -H "Authorization: Bearer $DEVIN_API_KEY"
```

<div id="next-steps">
  ## 后续步骤
</div>

* 浏览完整的 [API 权限参考文档](/zh/api-reference/v3/overview)
* 深入了解 [身份验证](/zh/api-reference/authentication)
* 为大型结果集设置 [分页](/zh/api-reference/concepts/pagination)
* 如果你正在从 v1/v2 迁移，请查看 [迁移指南](/zh/api-reference/getting-started/migration-guide)
