<span id="管理账户偏好"></span>

# Manage Account Preferences

Read the interface language and time zone settings of the authenticated account, submit updates, and re-read the preferences to confirm they took effect.

(sdk-ai-studio-preferences-flow)=
<span id="任务流程"></span>

## Task flow

```text
SDK client account handle
            │
            ▼
1. Read current account language (locale) and time zone (timezone)
            │
            ▼
2. Submit target language and time zone update
            │
            ▼
3. Re-read account preferences ──▶ Verify returned values match submitted values
```

(sdk-ai-studio-preferences-prepare)=
<span id="准备"></span>

## Prerequisites

1. Complete the endpoint, personal access token, and workspace setup in [Use the SDK](../../../quickstart/ai-studio/sdk.md).
2. Choose a supported locale identifier (such as `zh-CN` or `en-US`) and time zone name (such as `Asia/Shanghai` or `UTC`). Account preferences belong to the authenticated account directly and do not require binding a workspace.

Set the target locale and time zone in your terminal (any unset variable retains its current account value):

```bash
export TARGET_LOCALE='en-US'
export TARGET_TIMEZONE='UTC'
```

(sdk-ai-studio-preferences-s1)=
<span id="读取并更新偏好"></span>

## Read and update preferences

Read the current language and time zone first, submit the update request, and read back the preferences to verify that the saved values match.

:::::{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"],
)
before = client.account().preferences()
print("Current locale:", before.locale, "Current timezone:", before.timezone)

locale = os.environ.get("TARGET_LOCALE") or before.locale
timezone = os.environ.get("TARGET_TIMEZONE") or before.timezone

client.account().update_preferences(
    sdk.AuthPreferencesRequest(locale=locale, timezone=timezone)
)
current = client.account().preferences()
print("Saved locale:", current.locale, "Saved timezone:", current.timezone)
if current.locale != locale or current.timezone != timezone:
    raise RuntimeError("Read-back preferences do not match submitted values")
```

::::

::::{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)
	}
	before, err := client.Account().Preferences(ctx)
	if err != nil {
		panic(err)
	}
	fmt.Println("Current locale:", before.GetLocale(), "Current timezone:", before.GetTimezone())

	locale := os.Getenv("TARGET_LOCALE")
	if locale == "" {
		locale = before.GetLocale()
	}
	timezone := os.Getenv("TARGET_TIMEZONE")
	if timezone == "" {
		timezone = before.GetTimezone()
	}

	_, err = client.Account().UpdatePreferences(ctx, &sdk.AuthPreferencesRequest{
		Locale:   &locale,
		Timezone: &timezone,
	})
	if err != nil {
		panic(err)
	}
	current, err := client.Account().Preferences(ctx)
	if err != nil {
		panic(err)
	}
	fmt.Println("Saved locale:", current.GetLocale(), "Saved timezone:", current.GetTimezone())
	if current.GetLocale() != locale || current.GetTimezone() != timezone {
		panic("Read-back preferences do not match submitted values")
	}
}
```

::::

:::::

(sdk-ai-studio-preferences-limit)=
If an unsupported locale identifier or invalid time zone string is submitted, the server rejects the request with a validation error; correct the input values according to the error message and retry.

(sdk-ai-studio-preferences-next)=
<span id="下一步"></span>

## Next steps

- [Bind a Workspace](绑定工作区.md)
- [Configure Agent Output Language](../智能体/配置智能体输出语言.md)
