管理 API を使うと、ユーザーの招待、監査ログの確認、プロジェクトや API キーの管理、利用額の上限やアラートの設定、データ保持やレート制限の管理といった組織の管理業務を自動化できます。ダッシュボードの外でバックオフィス業務を自動化したり、セキュリティ関連のワークフローや運用ツールを実行したりする際に利用できます。
管理用の認証情報、ユーザーが所有するプロジェクトキー、ワークロード用のサービスアカウントの違いについては、API キーとサービスアカウントを参照してください。
各エンドポイントの詳細は、管理 API リファレンスを参照してください。管理 API キー、招待、ユーザー、プロジェクト、利用額の上限、監査ログの項目があります。
これらのエンドポイントにアクセスするには、管理 API キーを作成してください。管理 API キーは、管理用以外のエンドポイントでは使用できません。
各 SDK は以下のバージョンから管理 API に対応しています。お使いのバージョンによっては、SDK の更新が必要です。
- Node:
6.36.0
- Python:
2.34.0
- Go:
3.34.0
- Ruby:
0.61.0
- Java:
4.34.0
OPENAI_ADMIN_KEY を設定してから、使用する言語の SDK を初期化します。
1
2
3
4
5import OpenAI from "openai";
const client = new OpenAI({
adminAPIKey: process.env.OPENAI_ADMIN_KEY,
});
1
2
3
4
5
6import os
from openai import OpenAI
client = OpenAI(
admin_api_key=os.environ["OPENAI_ADMIN_KEY"],
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16package main
import (
"os"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/option"
)
func main() {
client := openai.NewClient(
option.WithAdminAPIKey(os.Getenv("OPENAI_ADMIN_KEY")),
)
_ = client
}
1
2
3
4
5import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
OpenAIClient client =
OpenAIOkHttpClient.builder().adminApiKey(System.getenv("OPENAI_ADMIN_KEY")).build();
1
2
3
4
5require "openai"
openai = OpenAI::Client.new(
admin_api_key: ENV.fetch("OPENAI_ADMIN_KEY")
)
プロジェクトのモデル権限設定で、許可リストまたは拒否リストを指定します。mode を allow_list に設定すると、リストにあるモデルだけが許可されます。mode を deny_list に設定すると、リストにあるモデルがブロックされ、それ以外の利用可能なモデルは許可されます。指定できるのは、組織から参照できるモデル ID に限られます。これには、組織から参照できるファインチューニング済みモデルのスナップショットの ID も含まれます。
1
2
3
4
5
6
7const modelPermissions =
await client.admin.organization.projects.modelPermissions.update("proj_abc", {
mode: "allow_list",
model_ids: ["gpt-4.1", "o3"],
});
console.log(modelPermissions.mode);
1
2
3
4
5
6
7model_permissions = client.admin.organization.projects.model_permissions.update(
"proj_abc",
mode="allow_list",
model_ids=["gpt-4.1", "o3"],
)
print(model_permissions.mode)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15ctx := context.Background()
modelPermissions, err := client.Admin.Organization.Projects.ModelPermissions.Update(
ctx,
"proj_abc",
openai.AdminOrganizationProjectModelPermissionUpdateParams{
Mode: openai.AdminOrganizationProjectModelPermissionUpdateParamsModeAllowList,
ModelIDs: []string{"gpt-4.1", "o3"},
},
)
if err != nil {
panic(err)
}
fmt.Println(modelPermissions.Mode)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18import com.openai.models.admin.organization.projects.modelpermissions.ModelPermissionUpdateParams;
import com.openai.models.admin.organization.projects.modelpermissions.ProjectModelPermissions;
import java.util.List;
ProjectModelPermissions modelPermissions =
client
.admin()
.organization()
.projects()
.modelPermissions()
.update(
"proj_abc",
ModelPermissionUpdateParams.builder()
.mode(ModelPermissionUpdateParams.Mode.ALLOW_LIST)
.modelIds(List.of("gpt-4.1", "o3"))
.build());
System.out.println(modelPermissions.mode());
1
2
3
4
5
6
7model_permissions = openai.admin.organization.projects.model_permissions.update(
"proj_abc",
mode: :allow_list,
model_ids: ["gpt-4.1", "o3"]
)
puts(model_permissions.mode)
利用額上限のエンドポイントを使うと、組織の月間利用額に強制上限を設定したり、既存の上限を置き換えたりできます。threshold_amount には金額をセント単位で指定します。次の例では、月間上限を 100 ドルに設定します。
12345678curl -X POST https://api.openai.com/v1/organization/spend_limit \
-H "Authorization: Bearer $OPENAI_ADMIN_KEY" \
-H "Content-Type: application/json" \
-d '{
"threshold_amount": 10000,
"currency": "USD",
"interval": "month"
}'
集計された利用額が強制上限に達すると、対象の API リクエストには 429 エラーが返されます。詳しくは、利用額上限のガイドを参照してください。
プロジェクトの利用額アラートを使うと、そのプロジェクトの利用額がしきい値に達したときにチームに通知できます。しきい値はセント単位で指定します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15const spendAlert = await client.admin.organization.projects.spendAlerts.create(
"proj_abc",
{
currency: "USD",
interval: "month",
notification_channel: {
recipients: ["billing@example.com"],
type: "email",
subject_prefix: "OpenAI spend",
},
threshold_amount: 50000,
}
);
console.log(spendAlert.id);
1
2
3
4
5
6
7
8
9
10
11
12
13spend_alert = client.admin.organization.projects.spend_alerts.create(
"proj_abc",
currency="USD",
interval="month",
notification_channel={
"recipients": ["billing@example.com"],
"type": "email",
"subject_prefix": "OpenAI spend",
},
threshold_amount=50000,
)
print(spend_alert.id)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21ctx := context.Background()
spendAlert, err := client.Admin.Organization.Projects.SpendAlerts.New(
ctx,
"proj_abc",
openai.AdminOrganizationProjectSpendAlertNewParams{
Currency: openai.AdminOrganizationProjectSpendAlertNewParamsCurrencyUsd,
Interval: openai.AdminOrganizationProjectSpendAlertNewParamsIntervalMonth,
NotificationChannel: openai.AdminOrganizationProjectSpendAlertNewParamsNotificationChannel{
Recipients: []string{"billing@example.com"},
Type: "email",
SubjectPrefix: openai.String("OpenAI spend"),
},
ThresholdAmount: 50000,
},
)
if err != nil {
panic(err)
}
fmt.Println(spendAlert.ID)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23import com.openai.models.admin.organization.projects.spendalerts.ProjectSpendAlert;
import com.openai.models.admin.organization.projects.spendalerts.SpendAlertCreateParams;
ProjectSpendAlert spendAlert =
client
.admin()
.organization()
.projects()
.spendAlerts()
.create(
"proj_abc",
SpendAlertCreateParams.builder()
.currency(SpendAlertCreateParams.Currency.USD)
.interval(SpendAlertCreateParams.Interval.MONTH)
.notificationChannel(
SpendAlertCreateParams.NotificationChannel.builder()
.addRecipient("billing@example.com")
.subjectPrefix("OpenAI spend")
.build())
.thresholdAmount(50000L)
.build());
System.out.println(spendAlert.id());
1
2
3
4
5
6
7
8
9
10
11
12
13spend_alert = openai.admin.organization.projects.spend_alerts.create(
"proj_abc",
currency: :USD,
interval: :month,
notification_channel: {
recipients: ["billing@example.com"],
type: :email,
subject_prefix: "OpenAI spend"
},
threshold_amount: 50_000
)
puts(spend_alert.id)
プロジェクトのデータ保持設定では、組織の保持ポリシーをプロジェクト単位で上書きするか、そのまま継承するかを選べます。組織の設定を継承するには、retention_type を organization_default に設定します。
1
2
3
4
5
6const dataRetention =
await client.admin.organization.projects.dataRetention.update("proj_abc", {
retention_type: "organization_default",
});
console.log(dataRetention.type);
1
2
3
4
5
6data_retention = client.admin.organization.projects.data_retention.update(
"proj_abc",
retention_type="organization_default",
)
print(data_retention.type)
1
2
3
4
5
6
7
8
9
10
11
12
13
14ctx := context.Background()
dataRetention, err := client.Admin.Organization.Projects.DataRetention.Update(
ctx,
"proj_abc",
openai.AdminOrganizationProjectDataRetentionUpdateParams{
RetentionType: openai.AdminOrganizationProjectDataRetentionUpdateParamsRetentionTypeOrganizationDefault,
},
)
if err != nil {
panic(err)
}
println(dataRetention.Type)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16import com.openai.models.admin.organization.projects.dataretention.DataRetentionUpdateParams;
import com.openai.models.admin.organization.projects.dataretention.ProjectDataRetention;
ProjectDataRetention dataRetention =
client
.admin()
.organization()
.projects()
.dataRetention()
.update(
"proj_abc",
DataRetentionUpdateParams.builder()
.retentionType(DataRetentionUpdateParams.RetentionType.ORGANIZATION_DEFAULT)
.build());
System.out.println(dataRetention.type());
1
2
3
4
5
6data_retention = openai.admin.organization.projects.data_retention.update(
"proj_abc",
retention_type: :organization_default
)
puts(data_retention.type)
招待エンドポイントを使うと、指定したメールアドレスに組織への招待を送信できます。
1
2
3
4
5
6const invite = await client.admin.organization.invites.create({
email: "user@example.com",
role: "reader",
});
console.log(invite.id);
1
2
3
4
5
6invite = client.admin.organization.invites.create(
email="user@example.com",
role="reader",
)
print(invite.id)
1
2
3
4
5
6
7
8
9
10
11ctx := context.Background()
invite, err := client.Admin.Organization.Invites.New(ctx, openai.AdminOrganizationInviteNewParams{
Email: "user@example.com",
Role: openai.AdminOrganizationInviteNewParamsRoleReader,
})
if err != nil {
panic(err)
}
fmt.Println(invite.ID)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15import com.openai.models.admin.organization.invites.Invite;
import com.openai.models.admin.organization.invites.InviteCreateParams;
Invite invite =
client
.admin()
.organization()
.invites()
.create(
InviteCreateParams.builder()
.email("user@example.com")
.role(InviteCreateParams.Role.READER)
.build());
System.out.println(invite.id());
1
2
3
4
5
6invite = openai.admin.organization.invites.create(
email: "user@example.com",
role: :reader
)
puts(invite.id)
監査ログのエンドポイントを使うと、組織内で最近行われたユーザー操作や設定変更の一覧を取得できます。
1
2
3
4
5const auditLogs = await client.admin.organization.auditLogs.list({
limit: 10,
});
console.log(auditLogs.data);
1
2
3
4audit_logs = client.admin.organization.audit_logs.list(limit=10)
for audit_log in audit_logs.data:
print(audit_log.id)
1
2
3
4
5
6
7
8
9
10
11
12ctx := context.Background()
auditLogs, err := client.Admin.Organization.AuditLogs.List(ctx, openai.AdminOrganizationAuditLogListParams{
Limit: openai.Int(10),
})
if err != nil {
panic(err)
}
for _, auditLog := range auditLogs.Data {
fmt.Println(auditLog.ID)
}
1
2
3
4
5
6
7
8
9
10import com.openai.models.admin.organization.auditlogs.AuditLogListParams;
var page =
client
.admin()
.organization()
.auditLogs()
.list(AuditLogListParams.builder().limit(10L).build());
page.data().forEach(auditLog -> System.out.println(auditLog.id()));
1
2
3
4
5audit_logs = openai.admin.organization.audit_logs.list(limit: 10)
(audit_logs.data || []).each do |audit_log|
puts(audit_log.id)
end