Skip to content

8. Open source edition uses CozeLoop SDK

qihai edited this page Jul 25, 2025 · 2 revisions

Coze Loop provides multi-language SDKs (Go, Python, and Node.js) to support developers in integrating Trace data reporting through standardized APIs. Coze Loop SDK supports authentication with Personal Access Tokens (PAT) to ensure secure and efficient interactions with Coze Loop services.

Coze Loop SDK

Coze Loop SDK supports integration with Eino and Langchain frameworks, enabling quick connectivity and data reporting for AI apps. Additionally, it also supports data reporting in a more flexible manner through Coze Loop's APIs.

SDK Download address Usage instructions
Coze Loop SDK for Go https://github.com/coze-dev/cozeloop-go Quickstart
Coze Loop SDK for Python https://github.com/coze-dev/cozeloop-python Quickstart
Coze Loop SDK for Node.js https://github.com/coze-dev/cozeloop-js Quickstart

The Coze Loop SDKs for three languages are applicable to both the commercial and open-source editions. For the open-source edition, developers only need to modify the following configuration during initialization:

Parameter Note
APIBaseURL The backend address deployed by the Coze Loop Open-source Edition.
WorkspaceId The workspace ID created in the Coze Loop open-source edition. You can refer to the SDK authorization for more information.
APIToken The Personal Access Token generated in the Coze Loop open-source edition. You can refer to the SDK authorization for more information.

Go SDK

Refer to the example code below to initialize the Coze Loop open-source edition client and report Trace using the API.

package main

import (
        "context"

        "[github.com/coze-dev/cozeloop-go](http://github.com/coze-dev/cozeloop-go)"
)

func main() {
        // Create client
        client, err := cozeloop.NewClient(
                cozeloop.WithAPIBaseURL("http://localhost:8888/"), // Open-source service deployment Host:Port
                cozeloop.WithAPIToken("your api token"),                        // You can apply within account settings
                cozeloop.WithWorkspaceID("your workspace id"),                     // Obtain workspace ID from the URL
                cozeloop.WithPromptTrace(true),
        )
        if err != nil {
                panic(err)
        }

        // Directly call the API
        ctx, span := client.StartSpan(context.Background(), "first_span", "custom")
        span.Finish(ctx)

        // Before the program exits, the Close method must be invoked; otherwise, trace data reporting may be lost. After Close, no further operations can be performed.
        client.Close(ctx)
}

Python SDK

Refer to the following sample code to initialize the Coze Loop Open-source Edition client and call the API to report Trace.

import cozeloop
import os

if __name__ == "__main__":
    # Set related environment variables
    os.environ["COZELOOP_WORKSPACE_ID"] = "your workspace id"
    os.environ["COZELOOP_API_TOKEN"] = "your api token"
    os.environ["COZELOOP_API_BASE_URL"] = "http://localhost:8888/"

    # Create the client
    client = cozeloop.new_client()

    # Call the API through the client
    span = client.start_span("first_span", "custom")
    span.finish()

    # Before the program exits, the Close method must be invoked; otherwise, trace data reporting may be lost. After Close, no further operations can be performed.
    cozeloop.close()

Node.js SDK

Refer to the following sample code to initialize the Coze Loop Open-source Edition client and call the API to report Trace.

import { cozeLoopTracer } from '@cozeloop/ai';

cozeLoopTracer.initialize({
  /** workspace id, use process.env.COZELOOP_WORKSPACE_ID when unprovided */
  workspaceId: 'your workspace id',
  apiClient: {
    baseURL: 'http://localhost:8888/',
    token: 'your api token',
  },
});
Clone this wiki locally