@@ -141,19 +141,13 @@ func (c *OpenAIClient) SetTimeout(timeout time.Duration) {
141141
142142// Project represents a project in OpenAI
143143type Project struct {
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"`
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"`
157151}
158152
159153// ProjectUser represents a user associated with a project
@@ -197,9 +191,7 @@ type APIKey struct {
197191
198192// CreateProjectRequest represents the request to create a project
199193type CreateProjectRequest struct {
200- Name string `json:"name"`
201- Description string `json:"description,omitempty"`
202- IsDefault bool `json:"is_default,omitempty"`
194+ Title string `json:"title"`
203195}
204196
205197// Error represents an error from the OpenAI API
@@ -567,23 +559,64 @@ type AssistantFunction struct {
567559 Parameters json.RawMessage `json:"parameters"`
568560}
569561
570- // User represents an OpenAI user
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
571584type User struct {
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"`
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+ }
578611}
579612
580613// UsersResponse represents the response from the list users API
581614type UsersResponse struct {
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"`
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"`
587620}
588621
589622// ListUsers retrieves a list of users in the organization
@@ -660,12 +693,13 @@ func (c *OpenAIClient) FindUserByEmail(email string) (*User, bool, error) {
660693 return nil , false , nil
661694 }
662695
663- // Return the first matching user
664- user := usersResponse .Data [0 ]
696+ // Return the first matching user (convert from OrganizationUser to User)
697+ orgUser := usersResponse .Data [0 ]
698+ user := orgUser .ToUser ()
665699
666700 // Double check that the email matches exactly (case insensitive)
667701 if strings .EqualFold (user .Email , email ) {
668- return & user , true , nil
702+ return user , true , nil
669703 }
670704
671705 // No exact match found
@@ -691,13 +725,14 @@ func (c *OpenAIClient) GetUser(userID string) (*User, bool, error) {
691725 return nil , false , fmt .Errorf ("error getting user: %w" , err )
692726 }
693727
694- // Parse the response
695- var user User
696- if err := json .Unmarshal (respBody , & user ); err != nil {
728+ // Parse the response into OrganizationUser (new API format)
729+ var orgUser OrganizationUser
730+ if err := json .Unmarshal (respBody , & orgUser ); err != nil {
697731 return nil , false , fmt .Errorf ("error decoding user response: %w" , err )
698732 }
699733
700- return & user , true , nil
734+ // Convert to flattened User struct
735+ return orgUser .ToUser (), true , nil
701736}
702737
703738// UpdateUserRole updates a user's role
@@ -719,13 +754,14 @@ func (c *OpenAIClient) UpdateUserRole(userID string, role string) (*User, error)
719754 return nil , fmt .Errorf ("error updating user role: %w" , err )
720755 }
721756
722- // Parse the response
723- var user User
724- if err := json .Unmarshal (respBody , & user ); err != nil {
757+ // Parse the response into OrganizationUser (new API format)
758+ var orgUser OrganizationUser
759+ if err := json .Unmarshal (respBody , & orgUser ); err != nil {
725760 return nil , fmt .Errorf ("error decoding user response: %w" , err )
726761 }
727762
728- return & user , nil
763+ // Convert to flattened User struct
764+ return orgUser .ToUser (), nil
729765}
730766
731767// DeleteUser removes a user from the organization
@@ -1075,25 +1111,15 @@ func (c *OpenAIClient) ListProjects(limit int, includeArchived bool, after strin
10751111 return & resp , nil
10761112}
10771113
1078- // CreateProject creates a new project with the given name and description
1079- func (c * OpenAIClient ) CreateProject (name , description string , isDefault bool ) (* Project , error ) {
1114+ // CreateProject creates a new project with the given title
1115+ func (c * OpenAIClient ) CreateProject (title string ) (* Project , error ) {
10801116 // Create the request body
10811117 requestBody := map [string ]interface {}{
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
1118+ "title" : title ,
10931119 }
10941120
10951121 // Debug information
1096- fmt .Printf ("Creating project with name : %s\n " , name )
1122+ fmt .Printf ("Creating project with title : %s\n " , title )
10971123 fmt .Printf ("Request body: %+v\n " , requestBody )
10981124
10991125 // Use the exact endpoint from the curl command that works
@@ -1140,21 +1166,11 @@ func (c *OpenAIClient) GetProject(id string) (*Project, error) {
11401166 return & project , nil
11411167}
11421168
1143- // UpdateProject updates an existing project with the given details
1144- func (c * OpenAIClient ) UpdateProject (id , name , description string , isDefault bool ) (* Project , error ) {
1169+ // UpdateProject updates an existing project with the given title
1170+ func (c * OpenAIClient ) UpdateProject (id , title string ) (* Project , error ) {
11451171 // Create the request body
11461172 requestBody := map [string ]interface {}{
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
1173+ "title" : title ,
11581174 }
11591175
11601176 // Use the exact endpoint structure consistent with the curl command
0 commit comments