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

# 设置用户的计费组织

> 为最多 100 个用户设置计费组织。

仅更改所提交用户的设置。即使部分分配无效，有效分配仍会一并保存，因此 `200` 响应中也可能包含失败项：请务必检查 `failed`。
错误响应表示未保存任何更改。重新提交分配会覆盖用户当前的计费组织，并新增一条审计日志记录。

通过一次请求为最多 100 个用户设置[计费组织](https://docs.devinenterprise.com/zh/admin/billing/org-acu-limits#billing-organization-attribution)。仅更改你提交的用户，企业中的其他用户不受影响。如需逐个设置单个用户，也可使用 beta 版[用户设置端点](https://docs.devinenterprise.com/zh/admin/billing/legacy-user-acu-limits#user-endpoints)，该端点同样接受 `billing_org_id`。

## 部分成功

即使同一请求中的其他行无效，有效的分配仍会一并保存，因此 `200` 响应中也可能包含失败项。请务必检查 `failed`：其中每个条目都会列出用户、所请求的组织以及 `reason`。这些用户的计费组织不会发生变化；请修正相应的行后重新发送。

| `reason` | 含义 |
| - | - |
| `user_not_found` | 该用户不是该企业的成员 (既不是直接成员，也未通过身份提供商组加入) 。 |
| `org_not_found` | 该组织不属于此企业。 |
| `user_not_org_member` | 该组织不是企业的主组织，且该用户不是该组织的成员。 |

今后可能会新增原因值，因此请将未知值作为失败项处理，而不是视为错误。

错误响应 (`4xx` 或 `5xx`) 表示请求中的所有内容均未保存。不包含任何分配、分配数超过 100 个，或同一 `user_id` 出现多次的请求将被拒绝，并返回 `422`。

重新发送某个分配会覆盖该用户当前的计费组织，并额外生成一条审计日志条目，因此重复调用是安全的，但并非毫无代价。

## 权限

需要一个在企业级别同时具有 `ManageBilling` 和 `ViewOrganizations` 权限的[服务用户](https://docs.devinenterprise.com/zh/api-reference/v3/service-users/members-service-users.md)或[个人访问令牌](https://docs.devinenterprise.com/zh/api-reference/personal-access-tokens.md)。`ManageOrganizations` 已包含 `ViewOrganizations`，因此同样满足该要求。


## OpenAPI

````yaml zh/v3-openapi.yaml PUT /v3/enterprise/members/users/billing-orgs
openapi: 3.1.0
info:
  description: 采用 Service User 身份验证和 RBAC 的 Devin v3 API
  title: Devin API v3
  version: 3.0.0
servers: []
security:
  - bearerAuth: []
paths:
  /v3/enterprise/members/users/billing-orgs:
    put:
      tags:
        - user-billing-orgs
      summary: 设置用户的计费组织
      description: |-
        为最多 100 个用户设置计费组织。

        仅更改所提交用户的设置。即使部分分配无效，有效分配仍会一并保存，因此 `200` 响应中也可能包含失败项：请务必检查 `failed`。
        错误响应表示未保存任何更改。重新提交分配会覆盖用户当前的计费组织，并新增一条审计日志记录。
      operationId: >-
        handle_update_user_billing_orgs_v3_enterprise_members_users_billing_orgs_put
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UserBillingOrgsUpdateRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserBillingOrgsUpdateResponse'
          description: 成功响应
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 未授权
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 禁止访问
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 未找到
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 冲突
        '410':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 已永久移除
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 无法处理的内容
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 请求过多
components:
  schemas:
    UserBillingOrgsUpdateRequest:
      properties:
        assignments:
          description: 要为各用户设置的计费组织。每个用户只能出现一次。
          items:
            $ref: '#/components/schemas/UserBillingOrgAssignmentRequest'
          maxItems: 100
          minItems: 1
          title: Assignments
          type: array
      required:
        - assignments
      title: UserBillingOrgsUpdateRequest
      type: object
    UserBillingOrgsUpdateResponse:
      properties:
        assigned:
          description: 已应用的分配。
          items:
            $ref: '#/components/schemas/UserBillingOrgAssignmentResponse'
          title: Assigned
          type: array
        failed:
          description: 已跳过的分配及其原因。这些用户的计费组织未发生变化。
          items:
            $ref: '#/components/schemas/UserBillingOrgFailureResponse'
          title: Failed
          type: array
      required:
        - assigned
        - failed
      title: UserBillingOrgsUpdateResponse
      type: object
    ProblemDetail:
      description: >-
        v3 API 的 RFC 9457 application/problem+json 错误响应体。


        detail 沿用自旧版 {"detail": ...} 响应体，以保持向后兼容；其他成员字段为新增字段。errors
        包含字段级验证失败信息（仅 422）。
      properties:
        detail:
          anyOf:
            - type: string
            - type: 'null'
          description: 针对此次具体情况的、便于人理解的说明。
          title: Detail
        error_code:
          anyOf:
            - type: string
            - type: 'null'
          description: 因操作被阻止而拒绝请求时返回的机器可读代码（例如 "user_frozen"、"migrated_session"）。
          title: Error Code
        errors:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          description: 字段级验证错误（仅适用于 422 响应）。
          title: Errors
        instance:
          anyOf:
            - type: string
            - type: 'null'
          description: 此次出现对应的 URI 引用（请求路径）。
          title: Instance
        status:
          description: HTTP 状态码。
          title: Status
          type: integer
        title:
          description: 对问题类型的简短、便于理解的概述。
          title: Title
          type: string
        type:
          default: about:blank
          description: 用于标识问题类型的 URI 引用。
          title: Type
          type: string
      required:
        - title
        - status
      title: ProblemDetail
      type: object
    UserBillingOrgAssignmentRequest:
      properties:
        billing_org_id:
          description: 该用户的 Devin Desktop 和 CLI 用量所归属的计费组织。
          title: Billing Org Id
          type: string
        user_id:
          description: 企业用户的 ID。
          title: User Id
          type: string
      required:
        - user_id
        - billing_org_id
      title: UserBillingOrgAssignmentRequest
      type: object
    UserBillingOrgAssignmentResponse:
      properties:
        billing_org_id:
          description: 该用户的 Devin Desktop 和 CLI 用量当前归属的计费组织。
          title: Billing Org Id
          type: string
        user_id:
          description: 企业用户的 ID。
          title: User Id
          type: string
      required:
        - user_id
        - billing_org_id
      title: UserBillingOrgAssignmentResponse
      type: object
    UserBillingOrgFailureResponse:
      properties:
        billing_org_id:
          description: 请求设置的计费组织 ID。
          title: Billing Org Id
          type: string
        reason:
          $ref: '#/components/schemas/UserBillingOrgFailureReason'
          description: 跳过分配的原因。如果目标组织不是企业的主要组织，用户必须是该组织的成员。后续可能会新增原因，因此需处理未知值。
        user_id:
          description: 未更新的用户的 ID。
          title: User Id
          type: string
      required:
        - user_id
        - billing_org_id
        - reason
      title: UserBillingOrgFailureResponse
      type: object
    UserBillingOrgFailureReason:
      enum:
        - user_not_found
        - org_not_found
        - user_not_org_member
      title: UserBillingOrgFailureReason
      type: string
  securitySchemes:
    bearerAuth:
      description: 服务用户凭据（前缀：cog_）
      scheme: bearer
      type: http

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.