Class: OpenAI::Resources::Admin::Organization::Projects::ServiceAccounts

Inherits:
Object
  • Object
show all
Defined in:
lib/openai/resources/admin/organization/projects/service_accounts.rb,
lib/openai/resources/admin/organization/projects/service_accounts/api_keys.rb,
sig/openai/resources/admin/organization/projects/service_accounts.rbs,
sig/openai/resources/admin/organization/projects/service_accounts/api_keys.rbs

Defined Under Namespace

Classes: APIKeys

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ ServiceAccounts

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ServiceAccounts.

Parameters:



189
190
191
192
# File 'lib/openai/resources/admin/organization/projects/service_accounts.rb', line 189

def initialize(client:)
  @client = client
  @api_keys = OpenAI::Resources::Admin::Organization::Projects::ServiceAccounts::APIKeys.new(client: client)
end

Instance Attribute Details

#api_keys ⇒ OpenAI::Resources::Admin::Organization::Projects::ServiceAccounts::APIKeys (readonly)



10
11
12
# File 'lib/openai/resources/admin/organization/projects/service_accounts.rb', line 10

def api_keys
  @api_keys
end

Instance Method Details

#create(project_id, name:, create_service_account_only: nil, expires_in_seconds: nil, request_options: {}) ⇒ OpenAI::Models::Admin::Organization::Projects::ServiceAccountCreateResponse

Creates a new service account in the project. By default, this also returns an unredacted API key for the service account.

Parameters:

  • project_id (String) —

    The ID of the project.

  • name (String) —

    The name of the service account being created.

  • create_service_account_only (Boolean, nil) —

    Create the service account without default roles or an API key.

  • expires_in_seconds (Integer, nil) —

    Number of seconds until the initial API key expires. If omitted or null, the key does not expire unless the effective organization or project policy requires an expiration. When a policy sets a maximum lifetime, this value must be provided and must not exceed that limit. A non-null value cannot be used when create_service_account_only is true.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/openai/resources/admin/organization/projects/service_accounts.rb', line 38

def create(project_id, params)
  parsed, options = OpenAI::Admin::Organization::Projects::ServiceAccountCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["organization/projects/%1$s/service_accounts", project_id],
    body: parsed,
    model: OpenAI::Models::Admin::Organization::Projects::ServiceAccountCreateResponse,
    security: {admin_api_key_auth: true},
    options: options
  )
end

#delete(service_account_id, project_id:, request_options: {}) ⇒ OpenAI::Models::Admin::Organization::Projects::ServiceAccountDeleteResponse

Deletes a service account from the project.

Returns confirmation of service account deletion, or an error if the project is archived (archived projects have no service accounts).

Parameters:

  • service_account_id (String) —

    The ID of the service account.

  • project_id (String) —

    The ID of the project.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/openai/resources/admin/organization/projects/service_accounts.rb', line 171

def delete(, params)
  parsed, options = OpenAI::Admin::Organization::Projects::ServiceAccountDeleteParams.dump_request(params)
  project_id = parsed.delete(:project_id) do
    raise ArgumentError.new("missing required path argument #{_1}")
  end

  @client.request(
    method: :delete,
    path: ["organization/projects/%1$s/service_accounts/%2$s", project_id, ],
    model: OpenAI::Models::Admin::Organization::Projects::ServiceAccountDeleteResponse,
    security: {admin_api_key_auth: true},
    options: options
  )
end

#list(project_id, after: nil, limit: nil, request_options: {}) ⇒ OpenAI::Internal::ConversationCursorPage<OpenAI::Models::Admin::Organization::Projects::ProjectServiceAccount>

Returns a list of service accounts in the project.

Parameters:

  • project_id (String) —

    The ID of the project.

  • after (String) —

    A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.

  • limit (Integer) —

    A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/openai/resources/admin/organization/projects/service_accounts.rb', line 139

def list(project_id, params = {})
  parsed, options = OpenAI::Admin::Organization::Projects::ServiceAccountListParams.dump_request(params)
  query = OpenAI::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["organization/projects/%1$s/service_accounts", project_id],
    query: query,
    page: OpenAI::Internal::ConversationCursorPage,
    model: OpenAI::Admin::Organization::Projects::ProjectServiceAccount,
    security: {admin_api_key_auth: true},
    options: options
  )
end

#retrieve(service_account_id, project_id:, request_options: {}) ⇒ OpenAI::Models::Admin::Organization::Projects::ProjectServiceAccount

Retrieves a service account in the project.

Parameters:

  • service_account_id (String) —

    The ID of the service account.

  • project_id (String) —

    The ID of the project.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/openai/resources/admin/organization/projects/service_accounts.rb', line 65

def retrieve(, params)
  parsed, options = OpenAI::Admin::Organization::Projects::ServiceAccountRetrieveParams.dump_request(params)
  project_id = parsed.delete(:project_id) do
    raise ArgumentError.new("missing required path argument #{_1}")
  end

  @client.request(
    method: :get,
    path: ["organization/projects/%1$s/service_accounts/%2$s", project_id, ],
    model: OpenAI::Admin::Organization::Projects::ProjectServiceAccount,
    security: {admin_api_key_auth: true},
    options: options
  )
end

#update(service_account_id, project_id:, name: nil, role: nil, request_options: {}) ⇒ OpenAI::Models::Admin::Organization::Projects::ProjectServiceAccount

Updates a service account in the project.

Parameters:

Returns:

See Also:



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/openai/resources/admin/organization/projects/service_accounts.rb', line 101

def update(, params)
  parsed, options = OpenAI::Admin::Organization::Projects::ServiceAccountUpdateParams.dump_request(params)
  project_id = parsed.delete(:project_id) do
    raise ArgumentError.new("missing required path argument #{_1}")
  end

  @client.request(
    method: :post,
    path: ["organization/projects/%1$s/service_accounts/%2$s", project_id, ],
    body: parsed,
    model: OpenAI::Admin::Organization::Projects::ProjectServiceAccount,
    security: {admin_api_key_auth: true},
    options: options
  )
end