Skip to content

feat: Admin Management Functionality #953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

MattDavisRV
Copy link
Contributor

A similar PR may already be submitted!
Please search among the Pull request before creating one.

If your changes introduce breaking changes, please prefix the title of your pull request with "[BREAKING_CHANGES]". This allows for clear identification of such changes in the 'What's Changed' section on the release page, making it developer-friendly.

Thanks for submitting a pull request! Please provide enough information so that others can review your pull request.

Describe the change
This change includes functionality to manage your Org via Admin API. This change does not include all endpoints and functionality related to the Admin API. As I have time, and if no one else has added them, I will submit another PR for the missing functionality.

Provide OpenAI documentation link
Admin API Documentation

Describe your solution
Implemented functionality to:

  • Manage Admin API Keys
  • Manage Organization Invites
  • Manage Organization Users
  • Manage Projects
  • Manage Project Users
  • View Organization Costs

Tests
Tests have been created for all functionality added. Test methodology was copied from existing tests in the library.

Additional context
I'm unsure why the Sanity checks are failing, they were locally as well, but unrelated to my changes (jsonschema).

Issue: #XXXX

Copy link

codecov bot commented Mar 11, 2025

Codecov Report

Attention: Patch coverage is 67.92453% with 119 lines in your changes missing coverage. Please review.

Project coverage is 83.01%. Comparing base (d7dca83) to head (3d2b63c).

Files with missing lines Patch % Lines
examples/admin_usage/main.go 0.00% 47 Missing ⚠️
admin_invite.go 74.13% 10 Missing and 5 partials ⚠️
admin_project.go 77.27% 10 Missing and 5 partials ⚠️
admin_project_user.go 77.27% 10 Missing and 5 partials ⚠️
admin_key.go 76.00% 8 Missing and 4 partials ⚠️
admin_user.go 76.47% 8 Missing and 4 partials ⚠️
admin_usage.go 90.90% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #953      +/-   ##
==========================================
- Coverage   85.43%   83.01%   -2.42%     
==========================================
  Files          43       50       +7     
  Lines        2313     2684     +371     
==========================================
+ Hits         1976     2228     +252     
- Misses        315      410      +95     
- Partials       22       46      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MattDavisRV
Copy link
Contributor Author

I add additional test cases to get a better coverage of the implementation. I believe this is failing the coverage now due to the example included. I see that other examples do not have test written for them, and I didn't see an obvious way to exclude it from being checked.

@MattDavisRV
Copy link
Contributor Author

@sashabaranov any chance this can be looked at?

@sashabaranov sashabaranov requested a review from Copilot June 16, 2025 19:21
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces the Admin Management functionality for managing API keys, org invites, users, projects, project users, and usage costs via the OpenAI Admin API.

  • Implements new endpoints in the client for various administrative operations.
  • Adds comprehensive tests for Admin Users, Projects, Project Users, API Keys, and Invites.
  • Updates examples and documentation to reflect the new Admin API features.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
examples/admin_usage/main.go Adds an example demonstrating Admin API usage cost retrieval.
examples/admin_usage/README.md Provides usage instructions for Admin API examples.
admin_user*.go & admin_user_test.go Implements and tests Admin Users management functions.
admin_usage*.go Implements and tests Admin Usage Cost functions.
admin_project*.go & admin_project_test.go Implements and tests Admin Projects management functions.
admin_project_user*.go Implements and tests Admin Project Users management functions.
admin_key*.go & admin_key_test.go Implements and tests Admin API Keys management functions.
admin_invite*.go & admin_invite_test.go Implements and tests Admin Invites management functions.
Comments suppressed due to low confidence (2)

admin_project_user.go:73

  • The parameter 'userID' in CreateAdminProjectUser is passed an email value in tests. Consider renaming it to 'userEmail' or updating its usage to ensure consistency.
func (c *Client) CreateAdminProjectUser(

admin_invite.go:97

  • Consider using a strict equality check for validating the admin role instead of a substring match, unless substring matching is intentionally desired.
if !containsSubstr(adminInviteRoles, role) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant