openaiorgs

package module
v0.2.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 9 Imported by: 0

README

openai-orgs - CLI for OpenAI Platform Management API

codecov

openai-orgs is a command-line interface (CLI) tool for interacting with the OpenAI Platform Administration APIs. It provides various commands to manage projects, users, API keys, service accounts, invites, and more.

Installation

To install openai-orgs, make sure you have Go installed on your system, then run:

go install github.com/klauern/openai-orgs/cmd/openai-orgs@latest

Configuration

Before using openai-orgs, you need to set up your OpenAI API key:

  1. Log in to your OpenAI account at https://platform.openai.com/
  2. Navigate to the API keys section
  3. Create a new API key
  4. Set the API key as an environment variable:
export OPENAI_API_KEY=your_api_key_here

Usage

openai-orgs uses subcommands to organize its functionality. Here are the main commands:

  • audit-logs: Manage audit logs
  • invites: Manage organization invites
  • users: Manage organization users
  • projects: Manage organization projects
  • project-users: Manage project users
  • project-service-accounts: Manage project service accounts
  • project-api-keys: Manage project API keys

To see available subcommands and options for each command, use the --help flag:

openai-orgs --help
openai-orgs <command> --help
Examples
  1. List all users in the organization:
openai-orgs users list
  1. Create a new project:
openai-orgs projects create --name "My New Project"
  1. List project API keys:
openai-orgs project-api-keys list --project-id <project_id>
  1. Create an invite:
openai-orgs invites create --email user@example.com --role member

Default Settings

  • The CLI uses the OpenAI API base URL: https://api.openai.com/v1
  • Authentication is handled using the OPENAI_API_KEY environment variable
  • List commands typically have optional --limit and --after flags to control pagination

Error Handling

If an error occurs during command execution, the CLI will display an error message and exit with a non-zero status code.

Contributing

Contributions to openai-orgs are welcome! Please submit issues and pull requests on the GitHub repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

View Source
const AuditLogsListEndpoint = "/organization/audit_logs"
View Source
const DefaultBaseURL = "https://api.openai.com/v1"
View Source
const InviteListEndpoint = "/organization/invites"
View Source
const ProjectApiKeysListEndpoint = "/organization/projects/%s/api_keys"
View Source
const ProjectServiceAccountsListEndpoint = "/organization/projects/%s/service_accounts"
View Source
const ProjectUsersListEndpoint = "/organization/projects/%s/users"
View Source
const ProjectsListEndpoint = "/organization/projects"
View Source
const UsersListEndpoint = "/organization/users"

Variables

This section is empty.

Functions

func Delete

func Delete[T any](client *resty.Client, endpoint string) error

func GetSingle

func GetSingle[T any](client *resty.Client, endpoint string) (*T, error)

func Post

func Post[T any](client *resty.Client, endpoint string, body interface{}) (*T, error)

Types

type APIKeyActor added in v0.2.11

type APIKeyActor struct {
	Type string    `json:"type"`
	User AuditUser `json:"user"`
}

APIKeyActor represents API key information in the actor field

type APIKeyCreated

type APIKeyCreated struct {
	ID   string `json:"id"`
	Data struct {
		Scopes []string `json:"scopes"`
	} `json:"data"`
}

Event types and their corresponding payload structures

type APIKeyDeleted

type APIKeyDeleted struct {
	ID string `json:"id"`
}

type APIKeyUpdated added in v0.2.11

type APIKeyUpdated struct {
	ID               string `json:"id"`
	ChangesRequested struct {
		Scopes []string `json:"scopes"`
	} `json:"changes_requested"`
}

type Actor

type Actor struct {
	Type    string       `json:"type"` // "session" or "api_key"
	Session *Session     `json:"session,omitempty"`
	APIKey  *APIKeyActor `json:"api_key,omitempty"`
}

Actor represents the entity performing the action

type AuditLog

type AuditLog struct {
	ID          string        `json:"id"`
	Type        string        `json:"type"`
	EffectiveAt UnixSeconds   `json:"effective_at"`
	Project     *AuditProject `json:"project,omitempty"`
	Actor       Actor         `json:"actor"`
	Details     interface{}   `json:"-"` // This will be unmarshaled based on Type
}

AuditLog represents the main audit log object

func (*AuditLog) UnmarshalJSON added in v0.2.11

func (a *AuditLog) UnmarshalJSON(data []byte) error

Add UnmarshalJSON to AuditLog to handle the event-specific details

type AuditLogListParams

type AuditLogListParams struct {
	EffectiveAt *EffectiveAt `json:"effective_at,omitempty"`
	ProjectIDs  []string     `json:"project_ids,omitempty"`
	EventTypes  []string     `json:"event_types,omitempty"`
	ActorIDs    []string     `json:"actor_ids,omitempty"`
	ActorEmails []string     `json:"actor_emails,omitempty"`
	ResourceIDs []string     `json:"resource_ids,omitempty"`
	Limit       int          `json:"limit,omitempty"`
	After       string       `json:"after,omitempty"`
	Before      string       `json:"before,omitempty"`
}

AuditLogListParams represents the query parameters for listing audit logs

type AuditLogListResponse added in v0.2.11

type AuditLogListResponse struct {
	Object  string     `json:"object"`
	Data    []AuditLog `json:"data"`
	FirstID string     `json:"first_id"`
	LastID  string     `json:"last_id"`
	HasMore bool       `json:"has_more"`
}

AuditLogListResponse represents the paginated response from the audit logs endpoint

type AuditProject added in v0.2.11

type AuditProject struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

AuditProject represents project information in audit logs

type AuditUser added in v0.2.11

type AuditUser struct {
	ID    string `json:"id"`
	Email string `json:"email"`
}

AuditUser represents user information in audit logs

type Client

type Client struct {
	BaseURL string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(baseURL, token string) *Client

func (*Client) ArchiveProject

func (c *Client) ArchiveProject(id string) (*Project, error)

func (*Client) CreateInvite

func (c *Client) CreateInvite(email string, role string) (*Invite, error)

func (*Client) CreateProject

func (c *Client) CreateProject(name string) (*Project, error)

func (*Client) CreateProjectServiceAccount

func (c *Client) CreateProjectServiceAccount(projectID string, name string) (*ProjectServiceAccount, error)

func (*Client) CreateProjectUser

func (c *Client) CreateProjectUser(projectID string, userID string, role string) (*ProjectUser, error)

func (*Client) DeleteInvite

func (c *Client) DeleteInvite(id string) error

func (*Client) DeleteProjectApiKey

func (c *Client) DeleteProjectApiKey(projectID string, apiKeyID string) error

func (*Client) DeleteProjectServiceAccount

func (c *Client) DeleteProjectServiceAccount(projectID string, serviceAccountID string) error

func (*Client) DeleteProjectUser

func (c *Client) DeleteProjectUser(projectID string, userID string) error

func (*Client) DeleteUser

func (c *Client) DeleteUser(id string) error

func (*Client) ListAuditLogs

func (c *Client) ListAuditLogs(params *AuditLogListParams) (*ListResponse[AuditLog], error)

func (*Client) ListInvites

func (c *Client) ListInvites() ([]Invite, error)

func (*Client) ListProjectApiKeys

func (c *Client) ListProjectApiKeys(projectID string, limit int, after string) (*ListResponse[ProjectApiKey], error)

func (*Client) ListProjectServiceAccounts

func (c *Client) ListProjectServiceAccounts(projectID string, limit int, after string) (*ListResponse[ProjectServiceAccount], error)

func (*Client) ListProjectUsers

func (c *Client) ListProjectUsers(projectID string, limit int, after string) (*ListResponse[ProjectUser], error)

func (*Client) ListProjects

func (c *Client) ListProjects(limit int, after string, includeArchived bool) (*ListResponse[Project], error)

func (*Client) ListUsers

func (c *Client) ListUsers(limit int, after string) (*ListResponse[User], error)

func (*Client) ModifyProject

func (c *Client) ModifyProject(id string, name string) (*Project, error)

func (*Client) ModifyProjectUser

func (c *Client) ModifyProjectUser(projectID string, userID string, role string) (*ProjectUser, error)

func (*Client) ModifyUserRole

func (c *Client) ModifyUserRole(id string, role string) error

func (*Client) RetrieveInvite

func (c *Client) RetrieveInvite(id string) (*Invite, error)

func (*Client) RetrieveProject

func (c *Client) RetrieveProject(id string) (*Project, error)

func (*Client) RetrieveProjectApiKey

func (c *Client) RetrieveProjectApiKey(projectID string, apiKeyID string) (*ProjectApiKey, error)

func (*Client) RetrieveProjectServiceAccount

func (c *Client) RetrieveProjectServiceAccount(projectID string, serviceAccountID string) (*ProjectServiceAccount, error)

func (*Client) RetrieveProjectUser

func (c *Client) RetrieveProjectUser(projectID string, userID string) (*ProjectUser, error)

func (*Client) RetrieveUser

func (c *Client) RetrieveUser(id string) (*User, error)

type EffectiveAt added in v0.2.14

type EffectiveAt struct {
	Gte int64 `json:"gte,omitempty"`
	Gt  int64 `json:"gt,omitempty"`
	Lte int64 `json:"lte,omitempty"`
	Lt  int64 `json:"lt,omitempty"`
}

type Invite

type Invite struct {
	ObjectType string       `json:"object"`
	ID         string       `json:"id"`
	Email      string       `json:"email"`
	Role       string       `json:"role"`
	Status     string       `json:"status"`
	CreatedAt  UnixSeconds  `json:"created_at"`
	ExpiresAt  UnixSeconds  `json:"expires_at"`
	AcceptedAt *UnixSeconds `json:"accepted_at,omitempty"`
}

type InviteAccepted added in v0.2.11

type InviteAccepted struct {
	ID string `json:"id"`
}

type InviteDeleted added in v0.2.11

type InviteDeleted struct {
	ID string `json:"id"`
}

type InviteSent

type InviteSent struct {
	ID   string `json:"id"`
	Data struct {
		Email string `json:"email"`
	} `json:"data"`
}

type ListResponse

type ListResponse[T any] struct {
	Object  string `json:"object"`
	Data    []T    `json:"data"`
	FirstID string `json:"first_id"`
	LastID  string `json:"last_id"`
	HasMore bool   `json:"has_more"`
}

Common response type for paginated lists

func Get

func Get[T any](client *resty.Client, endpoint string, queryParams map[string]string) (*ListResponse[T], error)

type LoginFailed added in v0.2.11

type LoginFailed struct {
	ErrorCode    string `json:"error_code"`
	ErrorMessage string `json:"error_message"`
}

type LoginSucceeded

type LoginSucceeded struct {
	Object      string `json:"object"`
	ID          string `json:"id"`
	Type        string `json:"type"`
	EffectiveAt int64  `json:"effective_at"`
	Actor       Actor  `json:"actor"`
}

type LogoutFailed added in v0.2.11

type LogoutFailed struct {
	ErrorCode    string `json:"error_code"`
	ErrorMessage string `json:"error_message"`
}

type OrganizationUpdated

type OrganizationUpdated struct {
	ID               string `json:"id"`
	ChangesRequested struct {
		Name string `json:"name,omitempty"`
	} `json:"changes_requested"`
}

type Owner

type Owner struct {
	Object string                 `json:"object"`
	ID     string                 `json:"id"`
	Name   string                 `json:"name"`
	Type   OwnerType              `json:"type"`
	User   *User                  `json:"user,omitempty"`
	SA     *ProjectServiceAccount `json:"service_account,omitempty"`
}

Common owner types

type OwnerType

type OwnerType string
const (
	OwnerTypeUser           OwnerType = "user"
	OwnerTypeServiceAccount OwnerType = "service_account"
)

type Project

type Project struct {
	Object     string       `json:"object"`
	ID         string       `json:"id"`
	Name       string       `json:"name"`
	CreatedAt  UnixSeconds  `json:"created_at"`
	ArchivedAt *UnixSeconds `json:"archived_at,omitempty"`
	Status     string       `json:"status"`
}

type ProjectApiKey

type ProjectApiKey struct {
	Object        string      `json:"object"`
	RedactedValue string      `json:"redacted_value"`
	Name          string      `json:"name"`
	CreatedAt     UnixSeconds `json:"created_at"`
	ID            string      `json:"id"`
	Owner         Owner       `json:"owner"`
}

type ProjectArchived added in v0.2.11

type ProjectArchived struct {
	ID string `json:"id"`
}

ProjectArchived represents the details for project.archived events

type ProjectCreated added in v0.2.11

type ProjectCreated struct {
	ID   string `json:"id"`
	Data struct {
		Name  string `json:"name"`
		Title string `json:"title"`
	} `json:"data"`
}

ProjectCreated represents the details for project.created events

type ProjectServiceAccount

type ProjectServiceAccount struct {
	Object    string                       `json:"object"`
	ID        string                       `json:"id"`
	Name      string                       `json:"name"`
	Role      string                       `json:"role"`
	CreatedAt UnixSeconds                  `json:"created_at"`
	APIKey    *ProjectServiceAccountAPIKey `json:"api_key,omitempty"`
}

type ProjectServiceAccountAPIKey added in v0.2.6

type ProjectServiceAccountAPIKey struct {
	Object    string      `json:"object"`
	Value     string      `json:"value"`
	Name      *string     `json:"name"`
	CreatedAt UnixSeconds `json:"created_at"`
	ID        string      `json:"id"`
}

type ProjectUpdated added in v0.2.11

type ProjectUpdated struct {
	ID               string `json:"id"`
	ChangesRequested struct {
		Title string `json:"title"`
	} `json:"changes_requested"`
}

ProjectUpdated represents the details for project.updated events

type ProjectUser

type ProjectUser struct {
	Object  string      `json:"object"`
	ID      string      `json:"id"`
	Name    string      `json:"name"`
	Email   string      `json:"email"`
	Role    string      `json:"role"`
	AddedAt UnixSeconds `json:"added_at"`
}

type RateLimitDeleted added in v0.2.11

type RateLimitDeleted struct {
	ID string `json:"id"`
}

RateLimitDeleted represents the details for rate_limit.deleted events

type RateLimitUpdated added in v0.2.11

type RateLimitUpdated struct {
	ID               string `json:"id"`
	ChangesRequested struct {
		MaxRequestsPer1Minute       int `json:"max_requests_per_1_minute,omitempty"`
		MaxTokensPer1Minute         int `json:"max_tokens_per_1_minute,omitempty"`
		MaxImagesPer1Minute         int `json:"max_images_per_1_minute,omitempty"`
		MaxAudioMegabytesPer1Minute int `json:"max_audio_megabytes_per_1_minute,omitempty"`
		MaxRequestsPer1Day          int `json:"max_requests_per_1_day,omitempty"`
		Batch1DayMaxInputTokens     int `json:"batch_1_day_max_input_tokens,omitempty"`
	} `json:"changes_requested"`
}

RateLimitUpdated represents the details for rate_limit.updated events

type RoleType

type RoleType string

Common role types

const (
	RoleTypeOwner  RoleType = "owner"
	RoleTypeMember RoleType = "member"
)

func ParseRoleType

func ParseRoleType(s string) RoleType

type ServiceAccountCreated added in v0.2.11

type ServiceAccountCreated struct {
	ID   string `json:"id"`
	Data struct {
		Role string `json:"role"` // Either "owner" or "member"
	} `json:"data"`
}

ServiceAccountCreated represents the details for service_account.created events

type ServiceAccountDeleted added in v0.2.11

type ServiceAccountDeleted struct {
	ID string `json:"id"`
}

ServiceAccountDeleted represents the details for service_account.deleted events

type ServiceAccountUpdated added in v0.2.11

type ServiceAccountUpdated struct {
	ID               string `json:"id"`
	ChangesRequested struct {
		Role string `json:"role"` // Either "owner" or "member"
	} `json:"changes_requested"`
}

ServiceAccountUpdated represents the details for service_account.updated events

type Session added in v0.2.11

type Session struct {
	User      AuditUser `json:"user"`
	IPAddress string    `json:"ip_address"`
	UserAgent string    `json:"user_agent"`
}

Session represents user session information

type UnixSeconds

type UnixSeconds time.Time

Common time handling

func (UnixSeconds) MarshalJSON

func (us UnixSeconds) MarshalJSON() ([]byte, error)

func (UnixSeconds) String

func (ct UnixSeconds) String() string

func (UnixSeconds) Time

func (ct UnixSeconds) Time() time.Time

func (*UnixSeconds) UnmarshalJSON

func (us *UnixSeconds) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface

type User

type User struct {
	Object  string      `json:"object"`
	ID      string      `json:"id"`
	Name    string      `json:"name"`
	Email   string      `json:"email"`
	Role    string      `json:"role"`
	AddedAt UnixSeconds `json:"added_at"`
}

User represents a user in the OpenAI organization

type UserAdded added in v0.2.11

type UserAdded struct {
	ID   string `json:"id"`
	Data struct {
		Role string `json:"role"` // Either "owner" or "member"
	} `json:"data"`
}

UserAdded represents the details for user.added events

type UserDeleted added in v0.2.11

type UserDeleted struct {
	ID string `json:"id"`
}

UserDeleted represents the details for user.deleted events

type UserUpdated added in v0.2.11

type UserUpdated struct {
	ID               string `json:"id"`
	ChangesRequested struct {
		Role string `json:"role"` // Either "owner" or "member"
	} `json:"changes_requested"`
}

UserUpdated represents the details for user.updated events

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL