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,27 @@
|
||||
// Route: POST /ai/openai/admin/usage, /costs, /audit
|
||||
#include "support/Assert.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
unsetenv("OPENAI_ADMIN_KEY");
|
||||
unsetenv("OPENAI_API_KEY");
|
||||
Fixture f;
|
||||
auto p = [&](const char* path, const std::string& b) {
|
||||
return f.client->post(std::string("/ai/openai/admin/") + path, b, "application/json");
|
||||
};
|
||||
check(p("usage", "{\"kind\":\"completions\",\"start_time\":1730419200}").status == 503, "usage without key is 503");
|
||||
check(p("usage", "{\"kind\":\"completions\"}").status == 422, "missing start_time is 422");
|
||||
check(p("usage", "{\"kind\":\"nope\",\"start_time\":1}").status == 422, "unknown kind is 422");
|
||||
check(p("usage", "{\"kind\":\"completions\",\"start_time\":1,\"limit\":999}").status == 422, "limit over cap is 422");
|
||||
check(p("usage", "{\"kind\":\"completions\",\"start_time\":1,\"sizes\":[\"1024x1024\"]}").status == 422, "foreign filter is 422");
|
||||
check(p("usage", "{\"kind\":\"images\",\"start_time\":1,\"group_by\":[\"size\"],\"walk\":true}").status == 503, "walk without key is 503");
|
||||
check(p("costs", "{\"start_time\":1730419200,\"limit\":7}").status == 503, "costs without key is 503");
|
||||
check(p("costs", "{\"start_time\":1730419200,\"limit\":181}").status == 422, "costs limit over 180 is 422");
|
||||
check(p("costs", "{\"start_time\":1,\"bucket_width\":\"1h\"}").status == 422, "costs are daily only");
|
||||
check(p("audit", "{\"limit\":20,\"event_types\":[\"project.created\"]}").status == 503, "audit without key is 503");
|
||||
check(p("audit", "{\"event_types\":[\"project.exploded\"]}").status == 422, "unknown event type is 422");
|
||||
check(p("audit", "{\"after\":\"a\",\"before\":\"b\"}").status == 422, "after and before together is 422");
|
||||
check(f.client->get("/ai/openai/admin/usage").status == 405, "get is 405");
|
||||
return finish("ai/openai/admin/usage");
|
||||
}
|
||||
Reference in New Issue
Block a user