Skip to content
Primary navigation

Create organization role

client.Admin.Organization.Roles.New(ctx, body) (*Role, error)
POST/organization/roles

Creates a custom role for the organization.

ParametersExpand Collapse
body AdminOrganizationRoleNewParams
Permissions param.Field[[]string]

Permissions to grant to the role.

RoleName param.Field[string]

Unique name for the role.

Description param.Field[string]Optional

Optional description of the role.

ReturnsExpand Collapse
type Role struct{…}

Details about a role that can be assigned through the public Roles API.

ID string

Identifier for the role.

Description string

Optional description of the role.

Name string

Unique name for the role.

Object Role

Always role.

Permissions []string

Permissions granted by the role.

PredefinedRole bool

Whether the role is predefined and managed by OpenAI.

ResourceType string

Resource type the role is bound to (for example api.organization or api.project).

Create organization role

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"),
  )
  role, err := client.Admin.Organization.Roles.New(context.TODO(), openai.AdminOrganizationRoleNewParams{
    Permissions: []string{"string"},
    RoleName: "role_name",
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", role.ID)
}
{
    "object": "role",
    "id": "role_01J1F8ROLE01",
    "name": "API Group Manager",
    "description": "Allows managing organization groups",
    "permissions": [
        "api.groups.read",
        "api.groups.write"
    ],
    "resource_type": "api.organization",
    "predefined_role": false
}
Returns Examples
{
    "object": "role",
    "id": "role_01J1F8ROLE01",
    "name": "API Group Manager",
    "description": "Allows managing organization groups",
    "permissions": [
        "api.groups.read",
        "api.groups.write"
    ],
    "resource_type": "api.organization",
    "predefined_role": false
}