Skip to content
For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Primary navigation

Create admin API key

client.Admin.Organization.AdminAPIKeys.New(ctx, body) (*AdminOrganizationAdminAPIKeyNewResponse, error)
POST/organization/admin_api_keys

Create an organization admin API key

ParametersExpand Collapse
body AdminOrganizationAdminAPIKeyNewParams
Name param.Field[string]
ExpiresInSeconds param.Field[int64]Optional

The number of seconds until the API key expires. Omit this field for a key that does not expire.

minimum1
maximum31536000
ReturnsExpand Collapse
type AdminOrganizationAdminAPIKeyNewResponse struct{…}

Represents an individual Admin API key in an org.

Value string

The value of the API key. Only shown on create.

Create admin API key

package main

import (
  "context"
  "fmt"

  "github.com/openai/openai-go"
  "github.com/openai/openai-go/option"
)

func main() {
  client := openai.NewClient(
    option.WithAdminAPIKey("My Admin API Key"),
  )
  adminAPIKey, err := client.Admin.Organization.AdminAPIKeys.New(context.TODO(), openai.AdminOrganizationAdminAPIKeyNewParams{
    Name: "New Admin Key",
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", adminAPIKey)
}
{
  "object": "organization.admin_api_key",
  "id": "key_xyz",
  "name": "New Admin Key",
  "redacted_value": "sk-admin...xyz",
  "created_at": 1711471533,
  "expires_at": 1714063533,
  "last_used_at": 1711471534,
  "owner": {
    "type": "user",
    "object": "organization.user",
    "id": "user_123",
    "name": "John Doe",
    "created_at": 1711471533,
    "role": "owner"
  },
  "value": "sk-admin-1234abcd"
}
Returns Examples
{
  "object": "organization.admin_api_key",
  "id": "key_xyz",
  "name": "New Admin Key",
  "redacted_value": "sk-admin...xyz",
  "created_at": 1711471533,
  "expires_at": 1714063533,
  "last_used_at": 1711471534,
  "owner": {
    "type": "user",
    "object": "organization.user",
    "id": "user_123",
    "name": "John Doe",
    "created_at": 1711471533,
    "role": "owner"
  },
  "value": "sk-admin-1234abcd"
}