# Bind Workspace

The AI Studio SDK scopes resources by workspace. This page describes how to bind a workspace using a known workspace ID and continue accessing data, workflows, connectors, and other resources within that scope.

(sdk-ai-studio-resource-model-relationship)=
## Object relationships

The client is responsible for authentication and dispatching requests. A workspace reference retains the workspace ID; resource references derived from it inherit the same workspace scope. Resource references hold identifiers and do not fetch, validate, or refresh remote resources upon creation.

```text
Client
└── Workspace
    ├── Data resources
    ├── Workflows and runs
    ├── Connectors and tasks
    └── Other workspace resources
```

(sdk-ai-studio-resource-model-bind-workspace)=
## Bind an existing workspace

Prepare a workspace ID obtained from creation, listing, or operator selection. The following example only binds the workspace; it does not create a workspace or query whether the ID exists. Subsequent examples should continue using the same workspace reference to avoid mistaking display names for resource IDs.

:::::{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>")
```

::::

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

```go
package main

import (
	"fmt"
	"os"

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

func main() {
	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)
	}
	fmt.Println(workspace.ID())
}
```

::::

:::::

If you need to find a workspace by name or create one when missing, refer to the corresponding quickstart workflow. That process looks up visible workspaces with matching names and may provision a new workspace, making it unsuitable for read-only operations.

(sdk-ai-studio-resource-model-read-workspace)=
## Read workspace-scoped information

After binding a workspace, you can read database connection parameters or recent failed audit records. Connection information may include sensitive configurations; use it only where establishing connections is required and do not write it to logs.

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

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

```python
connection = workspace.db_connection()
failed_logs = workspace.recent_failed_audit_logs(20)

print(connection)
print(failed_logs)
```

::::

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

```go
ctx := context.Background()
connection, err := workspace.DBConnection(ctx)
if err != nil {
	panic(err)
}
failedLogs, err := workspace.RecentFailedAuditLogs(ctx, 20)
if err != nil {
	panic(err)
}

_ = connection
_ = failedLogs
```

::::

:::::

Failed audit queries require a positive integer limit and only return failed records. Query results reflect the response of this request; if the next step relies on the current state of a resource, re-read it on that resource's task page.

(sdk-ai-studio-resource-model-next)=
## Next steps

- [Manage workspace members](管理工作区成员.md)
- [Run and track workflows](../数据处理/运行并跟踪工作流.md)
