@@ -141,13 +141,19 @@ func (c *OpenAIClient) SetTimeout(timeout time.Duration) {
141141
142142// Project represents a project in OpenAI
143143type Project struct {
144- ID string `json:"id"`
145- Object string `json:"object"`
146- Created int64 `json:"created"`
147- Status string `json:"status"`
148- ArchivedAt * int64 `json:"archived_at"`
149- IsInitial bool `json:"is_initial"`
150- Title string `json:"title"`
144+ Object string `json:"object"`
145+ ID string `json:"id"`
146+ Name string `json:"name"`
147+ Description string `json:"description,omitempty"`
148+ OrganizationID string `json:"organization_id,omitempty"`
149+ CreatedAt * int64 `json:"created_at"`
150+ ArchivedAt * int64 `json:"archived_at"`
151+ Status string `json:"status"`
152+ IsDefault bool `json:"is_default,omitempty"`
153+ BillingMode string `json:"billing_mode,omitempty"`
154+ APIKeys []APIKey `json:"api_keys,omitempty"`
155+ RateLimits []RateLimit `json:"rate_limits,omitempty"`
156+ Users []ProjectUser `json:"users,omitempty"`
151157}
152158
153159// ProjectUser represents a user associated with a project
@@ -191,7 +197,9 @@ type APIKey struct {
191197
192198// CreateProjectRequest represents the request to create a project
193199type CreateProjectRequest struct {
194- Title string `json:"title"`
200+ Name string `json:"name"`
201+ Description string `json:"description,omitempty"`
202+ IsDefault bool `json:"is_default,omitempty"`
195203}
196204
197205// Error represents an error from the OpenAI API
@@ -559,64 +567,23 @@ type AssistantFunction struct {
559567 Parameters json.RawMessage `json:"parameters"`
560568}
561569
562- // UserInfo represents the nested user details in an organization user response
563- type UserInfo struct {
564- ID string `json:"id"`
565- Object string `json:"object"`
566- Email string `json:"email"`
567- Name string `json:"name"`
568- }
569-
570- // OrganizationUser represents an OpenAI organization user as returned by the API
571- type OrganizationUser struct {
572- Object string `json:"object"`
573- Created int64 `json:"created"`
574- IsDefault bool `json:"is_default"`
575- IsScaleTierAuthorizedPurchaser bool `json:"is_scale_tier_authorized_purchaser"`
576- IsScimManaged bool `json:"is_scim_managed"`
577- IsServiceAccount bool `json:"is_service_account"`
578- Role string `json:"role"`
579- User UserInfo `json:"user"`
580- }
581-
582- // User provides a flattened view of OrganizationUser for easier access
583- // This is a convenience wrapper used internally
570+ // User represents an OpenAI user
584571type User struct {
585- ID string `json:"id"`
586- Object string `json:"object"`
587- Email string `json:"email"`
588- Name string `json:"name"`
589- Role string `json:"role"`
590- Created int64 `json:"created"`
591- IsDefault bool `json:"is_default"`
592- IsScaleTierAuthorizedPurchaser bool `json:"is_scale_tier_authorized_purchaser"`
593- IsScimManaged bool `json:"is_scim_managed"`
594- IsServiceAccount bool `json:"is_service_account"`
595- }
596-
597- // ToUser converts an OrganizationUser to a flattened User struct
598- func (ou * OrganizationUser ) ToUser () * User {
599- return & User {
600- ID : ou .User .ID ,
601- Object : ou .Object ,
602- Email : ou .User .Email ,
603- Name : ou .User .Name ,
604- Role : ou .Role ,
605- Created : ou .Created ,
606- IsDefault : ou .IsDefault ,
607- IsScaleTierAuthorizedPurchaser : ou .IsScaleTierAuthorizedPurchaser ,
608- IsScimManaged : ou .IsScimManaged ,
609- IsServiceAccount : ou .IsServiceAccount ,
610- }
572+ ID string `json:"id"`
573+ Object string `json:"object"`
574+ Email string `json:"email"`
575+ Name string `json:"name"`
576+ Role string `json:"role"`
577+ AddedAt int64 `json:"added_at"`
611578}
612579
613580// UsersResponse represents the response from the list users API
614581type UsersResponse struct {
615- Object string `json:"object"`
616- Data []OrganizationUser `json:"data"`
617- FirstID string `json:"first_id"`
618- LastID string `json:"last_id"`
619- HasMore bool `json:"has_more"`
582+ Object string `json:"object"`
583+ Data []User `json:"data"`
584+ FirstID string `json:"first_id"`
585+ LastID string `json:"last_id"`
586+ HasMore bool `json:"has_more"`
620587}
621588
622589// ListUsers retrieves a list of users in the organization
@@ -693,13 +660,12 @@ func (c *OpenAIClient) FindUserByEmail(email string) (*User, bool, error) {
693660 return nil , false , nil
694661 }
695662
696- // Return the first matching user (convert from OrganizationUser to User)
697- orgUser := usersResponse .Data [0 ]
698- user := orgUser .ToUser ()
663+ // Return the first matching user
664+ user := usersResponse .Data [0 ]
699665
700666 // Double check that the email matches exactly (case insensitive)
701667 if strings .EqualFold (user .Email , email ) {
702- return user , true , nil
668+ return & user , true , nil
703669 }
704670
705671 // No exact match found
@@ -725,14 +691,13 @@ func (c *OpenAIClient) GetUser(userID string) (*User, bool, error) {
725691 return nil , false , fmt .Errorf ("error getting user: %w" , err )
726692 }
727693
728- // Parse the response into OrganizationUser (new API format)
729- var orgUser OrganizationUser
730- if err := json .Unmarshal (respBody , & orgUser ); err != nil {
694+ // Parse the response
695+ var user User
696+ if err := json .Unmarshal (respBody , & user ); err != nil {
731697 return nil , false , fmt .Errorf ("error decoding user response: %w" , err )
732698 }
733699
734- // Convert to flattened User struct
735- return orgUser .ToUser (), true , nil
700+ return & user , true , nil
736701}
737702
738703// UpdateUserRole updates a user's role
@@ -754,14 +719,13 @@ func (c *OpenAIClient) UpdateUserRole(userID string, role string) (*User, error)
754719 return nil , fmt .Errorf ("error updating user role: %w" , err )
755720 }
756721
757- // Parse the response into OrganizationUser (new API format)
758- var orgUser OrganizationUser
759- if err := json .Unmarshal (respBody , & orgUser ); err != nil {
722+ // Parse the response
723+ var user User
724+ if err := json .Unmarshal (respBody , & user ); err != nil {
760725 return nil , fmt .Errorf ("error decoding user response: %w" , err )
761726 }
762727
763- // Convert to flattened User struct
764- return orgUser .ToUser (), nil
728+ return & user , nil
765729}
766730
767731// DeleteUser removes a user from the organization
@@ -1111,15 +1075,25 @@ func (c *OpenAIClient) ListProjects(limit int, includeArchived bool, after strin
11111075 return & resp , nil
11121076}
11131077
1114- // CreateProject creates a new project with the given title
1115- func (c * OpenAIClient ) CreateProject (title string ) (* Project , error ) {
1078+ // CreateProject creates a new project with the given name and description
1079+ func (c * OpenAIClient ) CreateProject (name , description string , isDefault bool ) (* Project , error ) {
11161080 // Create the request body
11171081 requestBody := map [string ]interface {}{
1118- "title" : title ,
1082+ "name" : name ,
1083+ }
1084+
1085+ // Only include description if it's not empty
1086+ if description != "" {
1087+ requestBody ["description" ] = description
1088+ }
1089+
1090+ // Only include is_default if it's true (don't send false)
1091+ if isDefault {
1092+ requestBody ["is_default" ] = isDefault
11191093 }
11201094
11211095 // Debug information
1122- fmt .Printf ("Creating project with title : %s\n " , title )
1096+ fmt .Printf ("Creating project with name : %s\n " , name )
11231097 fmt .Printf ("Request body: %+v\n " , requestBody )
11241098
11251099 // Use the exact endpoint from the curl command that works
@@ -1166,11 +1140,21 @@ func (c *OpenAIClient) GetProject(id string) (*Project, error) {
11661140 return & project , nil
11671141}
11681142
1169- // UpdateProject updates an existing project with the given title
1170- func (c * OpenAIClient ) UpdateProject (id , title string ) (* Project , error ) {
1143+ // UpdateProject updates an existing project with the given details
1144+ func (c * OpenAIClient ) UpdateProject (id , name , description string , isDefault bool ) (* Project , error ) {
11711145 // Create the request body
11721146 requestBody := map [string ]interface {}{
1173- "title" : title ,
1147+ "name" : name ,
1148+ }
1149+
1150+ // Only include description if it's not empty
1151+ if description != "" {
1152+ requestBody ["description" ] = description
1153+ }
1154+
1155+ // Only include is_default if it's true (don't send false)
1156+ if isDefault {
1157+ requestBody ["is_default" ] = isDefault
11741158 }
11751159
11761160 // Use the exact endpoint structure consistent with the curl command
0 commit comments