feat(clients): openai admin: organization admin API, usage, costs, audit logs, webhooks
121-call table checked against the OpenAI OpenAPI document, admin-key-only client, destructive guards, WebhookVerifier (Standard Webhooks HMAC-SHA256), demo routes under /ai/openai/admin, local and opt-in live tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
#pragma once
|
||||
|
||||
// Typed request bodies. Every class validates in `to_json()` (ranges and
|
||||
// enums taken from the OpenAPI document, ceilings from AdminCaps) and throws
|
||||
// llm::ApiError::invalid before anything is sent. Optional fields that are
|
||||
// unset are left out of the body, never sent as null.
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "clients/body/json.h"
|
||||
|
||||
namespace molo::openai::admin {
|
||||
|
||||
using Json = clients::body::Json;
|
||||
|
||||
// Longest expiry the API accepts for a key (1 year, spec maximum).
|
||||
constexpr std::int64_t kMaxKeyExpirySeconds = 31536000;
|
||||
|
||||
struct ProjectGrant {
|
||||
std::string id;
|
||||
std::string role; // member | owner
|
||||
};
|
||||
|
||||
struct InviteRequest {
|
||||
std::string email;
|
||||
std::string role; // reader | owner
|
||||
std::vector<ProjectGrant> projects;
|
||||
Json to_json() const;
|
||||
};
|
||||
|
||||
struct ProjectCreate {
|
||||
std::string name;
|
||||
std::string residency; // PublicProjectResidency value, optional
|
||||
std::string geography; // deprecated spelling, optional
|
||||
std::string external_key_id; // optional
|
||||
Json to_json() const;
|
||||
};
|
||||
|
||||
struct ProjectUpdate {
|
||||
std::string name;
|
||||
std::string external_key_id;
|
||||
std::string geography;
|
||||
Json to_json() const; // at least one field
|
||||
};
|
||||
|
||||
struct ProjectUserCreate {
|
||||
std::string user_id; // exactly one of user_id / email
|
||||
std::string email;
|
||||
std::string role; // owner | member
|
||||
Json to_json() const;
|
||||
};
|
||||
|
||||
struct UserUpdate {
|
||||
std::string role; // owner | reader
|
||||
std::string role_id;
|
||||
std::string technical_level;
|
||||
std::string developer_persona;
|
||||
Json to_json() const; // at least one field
|
||||
};
|
||||
|
||||
struct ServiceAccountCreate {
|
||||
std::string name;
|
||||
std::optional<bool> create_service_account_only;
|
||||
std::optional<std::int64_t> expires_in_seconds;
|
||||
Json to_json() const;
|
||||
};
|
||||
|
||||
struct ServiceAccountUpdate {
|
||||
std::string name;
|
||||
std::string role; // member | owner
|
||||
Json to_json() const; // at least one field
|
||||
};
|
||||
|
||||
struct ServiceAccountKeyCreate {
|
||||
std::string name;
|
||||
std::vector<std::string> scopes;
|
||||
std::optional<std::int64_t> expires_in_seconds;
|
||||
Json to_json() const;
|
||||
};
|
||||
|
||||
struct ProjectApiKeyUpdate {
|
||||
std::optional<std::int64_t> expires_in_seconds;
|
||||
std::optional<std::vector<std::string>> scopes; // empty vector removes the restriction
|
||||
Json to_json() const; // at least one field
|
||||
};
|
||||
|
||||
struct RateLimitUpdate {
|
||||
std::optional<std::int64_t> max_requests_per_1_minute;
|
||||
std::optional<std::int64_t> max_tokens_per_1_minute;
|
||||
std::optional<std::int64_t> max_images_per_1_minute;
|
||||
std::optional<std::int64_t> max_audio_megabytes_per_1_minute;
|
||||
std::optional<std::int64_t> max_requests_per_1_day;
|
||||
std::optional<std::int64_t> batch_1_day_max_input_tokens;
|
||||
Json to_json() const; // at least one field
|
||||
};
|
||||
|
||||
struct CertificateUpload {
|
||||
std::string name; // optional
|
||||
std::string certificate; // PEM
|
||||
Json to_json() const;
|
||||
};
|
||||
|
||||
// Spend alert: USD per month, threshold in cents (spec: integer, minimum 1).
|
||||
struct SpendAlertSpec {
|
||||
std::int64_t threshold_amount = 0;
|
||||
std::vector<std::string> recipients; // email channel, 1..10
|
||||
std::string subject_prefix; // optional
|
||||
Json to_json() const;
|
||||
};
|
||||
|
||||
struct SpendLimitSpec {
|
||||
std::int64_t threshold_amount = 0; // cents, minimum 1
|
||||
Json to_json() const;
|
||||
};
|
||||
|
||||
struct RoleSpec {
|
||||
std::string role_name;
|
||||
std::vector<std::string> permissions;
|
||||
std::string description; // optional
|
||||
Json to_json() const;
|
||||
};
|
||||
|
||||
struct RoleUpdate {
|
||||
std::string role_name;
|
||||
std::optional<std::vector<std::string>> permissions;
|
||||
std::string description;
|
||||
Json to_json() const; // at least one field
|
||||
};
|
||||
|
||||
struct ModelPermissions {
|
||||
std::string mode; // allow_list | deny_list
|
||||
std::vector<std::string> model_ids;
|
||||
Json to_json() const;
|
||||
};
|
||||
|
||||
// file_search, web_search, image_generation, mcp, code_interpreter -> enabled.
|
||||
struct HostedToolPermissions {
|
||||
std::map<std::string, bool> enabled;
|
||||
Json to_json() const; // at least one tool
|
||||
static const std::vector<std::string>& tools();
|
||||
};
|
||||
|
||||
// Retention types of the spec: organization and project enums differ.
|
||||
struct DataRetention {
|
||||
static Json organization(const std::string& retention_type);
|
||||
static Json project(const std::string& retention_type);
|
||||
};
|
||||
|
||||
struct ExternalStorageSpec {
|
||||
std::string project_id;
|
||||
std::string type; // aws | azure | gcp | oci
|
||||
std::map<std::string, std::string> provider; // fields of that provider, see SPEC
|
||||
Json to_json() const;
|
||||
};
|
||||
|
||||
struct WebhookEndpointSpec {
|
||||
std::string name;
|
||||
std::string url;
|
||||
std::vector<std::string> event_types;
|
||||
Json to_json(bool for_create) const; // update needs at least one field
|
||||
};
|
||||
|
||||
} // namespace molo::openai::admin
|
||||
Reference in New Issue
Block a user