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='https://api.moi.matrixorigin.cn/v5'
export PRODUCT_API_KEY='<your-personal-access-token>'

The SDK does not add a service address automatically. Use https://api.moi.matrixorigin.cn/v5. 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

AI Studio SDK features must be used in a workspace. Before using workflows, knowledge bases, data, agents, or other features, select the target workspace and get its workspace ID.

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())
	}
}

Select a target workspace ID from the output and save it as an environment variable:

export WORKSPACE_ID='<workspace-id>'

3. Call example

This example calls the List workflows feature. Use the connection details and workspace ID from the previous steps to create a workspace client and list the workflows that the current identity can read:

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(os.environ["WORKSPACE_ID"])
result = workspace.workflows().list()

print(result.total)
for workflow in result.workflows:
    print(workflow.id, workflow.name, workflow.status)
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 := client.Workspace(os.Getenv("WORKSPACE_ID"))
	result, err := workspace.Workflows().List(ctx)
	if err != nil {
		panic(err)
	}

	fmt.Println(result.GetTotal())
	for _, workflow := range result.GetWorkflows() {
		fmt.Printf("%s\t%s\t%s\n", workflow.GetId(), workflow.GetName(), workflow.GetStatus())
	}
}

On success, the program prints the workflow total followed by each workflow’s ID, name, and status.

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 is https://api.moi.matrixorigin.cn/v5. 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