# Manage Workspace Members

Use the AI Studio SDK to invite members and update their roles. The member ID returned from an invitation serves as the handover reference for reading member details and making subsequent role updates.

(sdk-ai-studio-workspace-member-flow)=
## Task workflow

First select the target workspace, then invite a member using one contact identifier. Email and phone invitations remain pending until accepted; when using a GitHub username, existing catalog users return a member ID immediately, while unmatched users return an empty ID until their first sign-in.

After obtaining a member ID, you can read member details, update roles, change status, or remove members. Role update requests do not return member details in the response, so a follow-up read is required for confirmation.

(sdk-ai-studio-workspace-member-prepare)=
## Prerequisites

| Required item | How to obtain | Role on this page |
| --- | --- | --- |
| Authenticated client | Created during the initial connection setup. | Access workspace resources. |
| Workspace ID | Obtained from workspace creation, listing, or operator selection. | Define the scope of member operations. |
| Member name and one contact identifier | Provided by an administrator. | Invite the member. |
| Assigned roles and default role | Selected by an administrator according to access policies. | Define the access scope for invitations or role updates. |

(sdk-ai-studio-workspace-member-invite)=
## Invite a member

The following example invites a member by email and stores the returned member ID. Provide exactly one identifier among email, phone number, and GitHub username; the role set must include the default role.

:::::{tab-set}
:sync-group: sdk-language

::::{tab-item} Python
:sync: python

```python
import os

import moi_product_sdk as sdk

client = sdk.new_with_personal_access_token(
    os.environ["PRODUCT_API_BASE_URL"],
    os.environ["PRODUCT_API_KEY"],
)
workspace = client.workspace("<workspace-id>")
default_role_id = 1
invitation = workspace.invite_member(
    "<member-name>",
    default_role_id,
    sdk.with_user_email("<member-email>"),
    sdk.with_user_role_ids(default_role_id),
)
member_id = invitation.id
print(member_id)
```

::::

::::{tab-item} Go
:sync: go

```go
package main

import (
	"context"
	"fmt"
	"os"

	sdk "github.com/matrixorigin/matrixflow/sdk/go-sdk"
)

func main() {
	ctx := context.Background()
	client, err := sdk.NewWithPersonalAccessToken(
		os.Getenv("PRODUCT_API_BASE_URL"),
		os.Getenv("PRODUCT_API_KEY"),
	)
	if err != nil {
		panic(err)
	}
	workspace, err := client.Workspace("<workspace-id>")
	if err != nil {
		panic(err)
	}
	const defaultRoleID = 1
	invitation, err := workspace.InviteMember(
		ctx,
		"<member-name>",
		defaultRoleID,
		sdk.WithUserEmail("<member-email>"),
		sdk.WithUserRoleIDs(defaultRoleID),
	)
	if err != nil {
		panic(err)
	}
	fmt.Println(invitation.GetId())
}
```

::::

:::::

An empty member ID indicates that follow-up member update operations cannot yet proceed. Wait until the user completes sign-in or accepts the invitation, then obtain the active ID from the member list or member details.

(sdk-ai-studio-workspace-member-confirm)=
## Confirm member roles

After updating roles using the member ID obtained in the previous step, read the member details to confirm the change. A role update response only indicates request completion; when subsequent logic depends on the access scope, verify against the newly read member information.

:::::{tab-set}
:sync-group: sdk-language

::::{tab-item} Python
:sync: python

```python
member = workspace.member(member_id)
role_id = 1
member.set_roles([role_id], role_id)
member_info = member.info()
print(member_info)
```

::::

::::{tab-item} Go
:sync: go

```go
member, err := workspace.Member(memberID)
if err != nil {
	panic(err)
}
roleID := 1
if err := member.SetRoles(ctx, []int{roleID}, roleID); err != nil {
	panic(err)
}
memberInfo, err := member.Info(ctx)
if err != nil {
	panic(err)
}
_ = memberInfo
```

::::

:::::

(sdk-ai-studio-workspace-member-current-role)=
## Select the current role for the Go client

The Go client allows configuring the current active role for a specific workspace upon client creation. The role ID must be a positive decimal integer without leading zeros; this configuration applies only to requests targeting that workspace. Python currently does not provide an equivalent client-level configuration.

```go
client, err := sdk.NewWithPersonalAccessToken(
	os.Getenv("PRODUCT_API_BASE_URL"),
	os.Getenv("PRODUCT_API_KEY"),
	sdk.WithWorkspaceCurrentRoleID("<workspace-id>", "<role-id>"),
)
if err != nil {
	panic(err)
}
_ = client
```

(sdk-ai-studio-workspace-member-next)=
## Next steps

- [Manage volumes and files](../资源中心/管理卷和文件.md)
- [Run and track workflows](../数据处理/运行并跟踪工作流.md)
