Use the SDK

Use the AI Studio SDK to work with workspace-scoped Product resources in Go or Python applications. After completing this page, you will use a personal access token to list visible workspaces and obtain the workspace ID required for later tasks.

For all scenarios and task guides, see AI Studio SDK.

Prerequisites: Get the SDK

Before starting, go to Download AI Studio SDK to obtain the offline distribution package for your language (Python wheel or Go source module), then install and verify dependencies locally.

1. Create a client and authenticate

export PRODUCT_API_BASE_URL='<Product API Base URL ending in /newmoi>'
export PRODUCT_API_KEY='<your-personal-access-token>'

The SDK does not add /newmoi automatically. Pass the personal access token as its original value; the client sends it in X-API-Key. Do not add a Bearer prefix or use a Genesis API endpoint.

2. List visible workspaces

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"],
)
result = client.workspaces().list()
for workspace in result.workspaces:
    print(workspace.id, workspace.name)
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)
	}
	result, err := client.Workspaces().List(ctx)
	if err != nil {
		panic(err)
	}
	for _, workspace := range result.GetWorkspaces() {
		fmt.Printf("%s\t%s\n", workspace.GetId(), workspace.GetName())
	}
}

A successful list response confirms that the endpoint and personal access token can be used for workspace discovery.

3. Enter a workspace

Choose a returned workspace ID, then use client.workspace(workspace_id) in Python or client.Workspace(workspaceID) in Go to enter workspace scope. This binding does not access the service. Do not use ensure_workspace or EnsureWorkspace, which can create a workspace, to verify connectivity.

If you receive 401, check that the token is complete and has no Bearer prefix. If you receive 404 or HTML content, check that the endpoint includes /newmoi. If the list is empty or you receive 403, confirm that the current account has the required workspace member or role permissions.

Next steps

Last updated on