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.
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.
Client
└── Workspace
├── Data resources
├── Workflows and runs
├── Connectors and tasks
└── Other workspace resources
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.
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>")
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.
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.
connection = workspace.db_connection()
failed_logs = workspace.recent_failed_audit_logs(20)
print(connection)
print(failed_logs)
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.