Claude Platform Docs

建立服務帳戶

client.Organization.ServiceAccounts.New(ctx, body) (*ServiceAccount, error)
POST/v1/organizations/service_accounts

需要具有 org:admin 範圍的 OAuth 存取權杖,可透過 ant auth login --scope org:admin 或工作負載身分聯合(workload identity federation)規則取得;不接受 Admin API 金鑰。請參閱使用 Admin API 管理 WIF。

建立服務帳戶。

服務帳戶是聯合規則所指向的具名工作負載身分。organization_role 為 developer(預設)或 admin;只有當目標的 organization_role 為 admin 時,才能建立或重新指定規則以授予 org:admin 範圍。建立 admin 角色的服務帳戶需要互動式憑證(使用者 OAuth 權杖或 Console 工作階段)——工作負載只能建立 developer 角色的服務帳戶。

Parameters
body OrganizationServiceAccountNewParams
Name string

Slug identifier (lowercase, digits, hyphens). Unique within the organization; a duplicate name returns 409.

minLength1
maxLength255
Description param.Opt[string] Optional

Optional free-text description.

maxLength2000

Org-level role. Defaults to developer.

const OrganizationServiceAccountNewParamsOrganizationRoleAdmin OrganizationServiceAccountNewParamsOrganizationRole = "admin"
const OrganizationServiceAccountNewParamsOrganizationRoleDeveloper OrganizationServiceAccountNewParamsOrganizationRole = "developer"
Returns
type ServiceAccount struct { Type: "service_account"; ID; ArchivedAt; /* 8 more */ }

Named non-human identity within the caller's organization.

A service account is a pure identity: name + org. Authorization lives on whatever references it (federation rules).

建立服務帳戶
package main

import (
	"context"
	"fmt"

	"github.com/anthropics/anthropic-sdk-go"
	"github.com/anthropics/anthropic-sdk-go/option"
)

func main() {
	client := anthropic.NewClient(
		option.WithAPIKey("my-anthropic-api-key"),
	)
	serviceAccount, err := client.Organization.ServiceAccounts.New(context.TODO(), anthropic.OrganizationServiceAccountNewParams{
		Name: "ci-deploy-bot",
	})
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", serviceAccount.ID)
}
Returns Examples
Response 200
{
  "id": "svac_01SDCCSbTxrXDpWc1phhtcfK",
  "archived_at": "2019-12-27T18:11:19.117Z",
  "archived_by_actor_id": "archived_by_actor_id",
  "created_at": "2024-10-30T23:58:27.427722Z",
  "created_by_actor_id": "created_by_actor_id",
  "description": "description",
  "name": "ci-deploy-bot",
  "organization_role": "admin",
  "type": "service_account",
  "updated_at": "2024-10-30T23:58:27.427722Z",
  "updated_by_actor_id": "updated_by_actor_id"
}