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:
2026-10-24 07:43:17 +02:00
co-authored by Claude Sonnet 5.5
parent 2e0270c043
commit 9e550889cc
47 changed files with 5533 additions and 3 deletions
+53
View File
@@ -0,0 +1,53 @@
#pragma once
// Query strings. `Query` is an ordered, validated, percent-encoded parameter
// list; `ListOptions` is the id-cursor paging every list call shares.
// Array filters repeat the name ("project_ids=a&project_ids=b", the form the
// OpenAPI document declares); names that the spec spells with brackets
// ("project_ids[]" on audit logs) are passed with the brackets.
#include <cstdint>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "openai/admin/calls.h"
namespace molo::openai::admin {
class Query {
public:
Query& set(const std::string& name, const std::string& value);
Query& set_int(const std::string& name, std::int64_t value);
Query& set_bool(const std::string& name, bool value);
// One "name=value" pair per entry; entries are capped.
Query& add_all(const std::string& name, const std::vector<std::string>& values);
bool empty() const { return pairs_.empty(); }
std::size_t size() const { return pairs_.size(); }
const std::vector<std::pair<std::string, std::string>>& pairs() const { return pairs_; }
bool has(const std::string& name) const;
// Throws unless every name is a query parameter of the call (table).
void check_against(Call call) const;
// "?a=1&b=2" or "" (percent-encoded, deterministic order of insertion).
std::string encoded() const;
static std::string escape(const std::string& text);
private:
std::vector<std::pair<std::string, std::string>> pairs_;
};
// limit / after / before / order of the id-cursor lists. Which of them a call
// takes is decided by the call table; sending one the call lacks throws.
struct ListOptions {
std::optional<int> limit; // 1..100
std::string after;
std::string before;
std::string order; // "asc" or "desc"
Query to_query() const;
};
} // namespace molo::openai::admin