Class: Braintrust::Resources::APIKeys

Inherits:
Object
  • Object
show all
Defined in:
lib/braintrust/resources/api_keys.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ APIKeys

Returns a new instance of APIKeys.



6
7
8
# File 'lib/braintrust/resources/api_keys.rb', line 6

def initialize(client:)
  @client = client
end

Instance Method Details

#create(params = {}, opts = {}) ⇒ Braintrust::Models::CreateAPIKeyOutput

Create a new api_key. It is possible to have multiple API keys with the same name. There is no de-duplication

Parameters:

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :name (String)

    Name of the api key. Does not have to be unique

  • :org_name (String)

    For nearly all users, this parameter should be unnecessary. But in the rare case that your API key belongs to multiple organizations, you may specify the name of the organization the API key belongs in.

Returns:



22
23
24
25
26
27
28
29
# File 'lib/braintrust/resources/api_keys.rb', line 22

def create(params = {}, opts = {})
  req = {}
  req[:method] = :post
  req[:path] = "/v1/api_key"
  req[:body] = params
  req[:model] = Braintrust::Models::CreateAPIKeyOutput
  @client.request(req, opts)
end

#delete(api_key_id, opts = {}) ⇒ Braintrust::Models::APIKey

Delete an api_key object by its id

Parameters:

  • api_key_id (String)

    ApiKey id

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Returns:



84
85
86
87
88
89
90
# File 'lib/braintrust/resources/api_keys.rb', line 84

def delete(api_key_id, opts = {})
  req = {}
  req[:method] = :delete
  req[:path] = "/v1/api_key/#{api_key_id}"
  req[:model] = Braintrust::Models::APIKey
  @client.request(req, opts)
end

#list(params = {}, opts = {}) ⇒ Braintrust::ListObjects<Braintrust::Models::APIKey>

List out all api_keys. The api_keys are sorted by creation date, with the most recently-created api_keys coming first

Parameters:

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :api_key_name (String)

    Name of the api_key to search for

  • :ending_before (String)

    Pagination cursor id.

    For example, if the initial item in the last page you fetched had an id of foo, pass ending_before=foo to fetch the previous page. Note: you may only pass one of starting_after and ending_before

  • :ids (Array<String>|String)

    Filter search results to a particular set of object IDs. To specify a list of IDs, include the query param multiple times

  • :limit (Integer)

    Limit the number of objects to return

  • :org_name (String)

    Filter search results to within a particular organization

  • :starting_after (String)

    Pagination cursor id.

    For example, if the final item in the last page you fetched had an id of foo, pass starting_after=foo to fetch the next page. Note: you may only pass one of starting_after and ending_before

Returns:



68
69
70
71
72
73
74
75
76
# File 'lib/braintrust/resources/api_keys.rb', line 68

def list(params = {}, opts = {})
  req = {}
  req[:method] = :get
  req[:path] = "/v1/api_key"
  req[:query] = params
  req[:page] = Braintrust::ListObjects
  req[:model] = Braintrust::Models::APIKey
  @client.request(req, opts)
end

#retrieve(api_key_id, opts = {}) ⇒ Braintrust::Models::APIKey

Get an api_key object by its id

Parameters:

  • api_key_id (String)

    ApiKey id

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Returns:



37
38
39
40
41
42
43
# File 'lib/braintrust/resources/api_keys.rb', line 37

def retrieve(api_key_id, opts = {})
  req = {}
  req[:method] = :get
  req[:path] = "/v1/api_key/#{api_key_id}"
  req[:model] = Braintrust::Models::APIKey
  @client.request(req, opts)
end