SDKs
The SDKs call the Conversation API from Go and TypeScript. They are generated from the API’s OpenAPI definition, so they have the same operations and fields as the API reference. The guide explains what each call does. This page covers what is particular to the SDKs.
| Language | Package | Source |
|---|---|---|
| Go | github.com/partite-ai/sdk-go | partite-ai/sdk-go |
| TypeScript | @partite-ai/sdk | partite-ai/sdk-typescript |
What the SDKs cover
- Conversations: start one, with or without a first message, get one, and list its intents and requests.
- Requests: send a message, get a request, wait for it, stream its events and cancel it.
- Tasks: complete or cancel an open task.
- Files: attach files to a message, and add files to a conversation and list them. The SDKs also download the content of a resource.
- Notification channels: create one and read its events.
They do not cover:
- Configuration, such as meshes, agents and models. Use the UI, the CLI, Terraform or the GraphQL API.
- AG-UI, meshes as MCP servers, webhooks and traces.
- Getting a token from an access point. Get the token yourself, and give it to the SDK.
- Streaming from the call that sends a message. Send the message, then stream the request’s events with a second call.
Go
The module needs Go 1.26 or later.
go get github.com/partite-ai/sdk-goThis program starts a conversation with a first message and waits for the answer. Then it sends a second message and streams the events of the request it starts.
package main
import (
"context"
"errors"
"fmt"
"io"
"log"
partiteai "github.com/partite-ai/sdk-go"
"github.com/partite-ai/sdk-go/client"
)
func main() {
ctx := context.Background()
c := client.NewClient() // reads the token from PARTITE_API_KEY
// Start a conversation with a first message, and wait up to 50 seconds for the answer.
conversation, err := c.Conversations.CreateConversation(ctx, &partiteai.CreateConversationRequest{
Wait: partiteai.Int(50),
Params: &partiteai.CreateConversationParams{
Mesh: &partiteai.ConversationMesh{ID: "<MESH_ID>", VersionLabel: partiteai.String("prod")},
Intent: partiteai.String("AnalyzeIssue"),
Input: map[string]any{"issueText": "App crashes when saving after upgrade to v2.3"},
},
})
if err != nil {
log.Fatal(err)
}
first := conversation.Request
if first.Status == partiteai.RequestStatusCompleted {
fmt.Println("response:", first.Response)
} else {
fmt.Println("status:", first.Status)
}
// Send another message, and stream the events of the request it starts.
request, err := c.Conversations.CreateRequest(ctx, &partiteai.CreateRequestRequest{
ConversationID: conversation.ID,
Params: &partiteai.CreateRequestParams{
Input: map[string]any{"issueText": "It also crashes on export"},
},
})
if err != nil {
log.Fatal(err)
}
stream, err := c.Conversations.StreamRequestEvents(ctx, &partiteai.StreamRequestEventsRequest{
ConversationID: conversation.ID,
RequestID: request.ID,
})
if err != nil {
log.Fatal(err)
}
defer stream.Close()
for {
event, err := stream.Recv()
if errors.Is(err, io.EOF) {
return
}
if err != nil {
log.Fatal(err)
}
switch event.Type {
case "message":
fmt.Println("message:", event.Message.Data)
case "task":
fmt.Println("the request waits for a task")
return
case "response":
fmt.Println("response:", event.Response.Data)
return
case "error":
fmt.Println("error:", event.Error.Data)
return
case "cancelled":
fmt.Println("cancelled")
return
}
}
}- Optional fields are pointers.
partiteai.String,partiteai.Intandpartiteai.Boolmake them. event.Typesays which field of the event is set:Message,Thinking,Task,TaskResponse,Response,Error,CancelledorServerError.- A stream stays open while the request waits on a task. Close it when you are done.
- An error from the API wraps a
*core.APIError(packagegithub.com/partite-ai/sdk-go/core), which has theStatusCode. Get it witherrors.As.
TypeScript
The package needs Node.js 18 or later.
npm install @partite-ai/sdkThis program does the same as the Go program above.
import { PartiteAiClient } from "@partite-ai/sdk";
const client = new PartiteAiClient(); // reads the token from PARTITE_API_KEY
// Start a conversation with a first message, and wait up to 50 seconds for the answer.
const conversation = await client.conversations.createConversation({
wait: 50,
params: {
mesh: { id: "<MESH_ID>", versionLabel: "prod" },
intent: "AnalyzeIssue",
input: { issueText: "App crashes when saving after upgrade to v2.3" },
},
});
const first = conversation.request!;
if (first.status === "completed") {
console.log("response:", first.response);
} else {
console.log("status:", first.status);
}
// Send another message, and stream the events of the request it starts.
const request = await client.conversations.createRequest({
conversationId: conversation.id,
params: { input: { issueText: "It also crashes on export" } },
});
const events = await client.conversations.streamRequestEvents({
conversationId: conversation.id,
requestId: request.id,
});
for await (const event of events) {
if (event.type === "message") {
console.log("message:", event.data);
} else if (event.type === "task") {
console.log("the request waits for a task");
break;
} else if (event.type === "response") {
console.log("response:", event.data);
break;
} else if (event.type === "error") {
console.log("error:", event.data);
break;
} else if (event.type === "cancelled") {
console.log("cancelled");
break;
}
}- Field names are in camelCase, such as
versionLabelandconversationId. The SDK sends them with the API’s names. - Leaving the
for awaitloop closes the stream. - An error from the API is thrown as a
PartiteAiError, which has thestatusCode, and the problem document inbody.
Wait or stream
A request is usually still running when the call that starts it returns. There are two ways to get the result:
- Wait. Set
Wait(Go) orwait(TypeScript) on the call that starts the request, or on the call that gets it. The call returns when the request leavesrunning, or after that many seconds. The maximum is 50. If the request is stillrunning, get it again with a wait. - Stream. Stream the request’s events. The
response,errorandcancelledevents end the request.
A server_error event means the server could not read the stream further. To resume, stream again with LastEventID (Go) or lastEventId (TypeScript) set to the ID of the last event you got.
Authenticate
The SDKs send a bearer token. By default they read it from the environment variable PARTITE_API_KEY. To pass it in the code:
| Go | TypeScript | |
|---|---|---|
| A token | client.NewClient(option.WithAPIKey(token)) | new PartiteAiClient({ apiKey: token }) |
| A function that returns the current token | option.WithAPIKeyFunc(func() (string, error) { ... }) | apiKey: async () => ... |
option is the package github.com/partite-ai/sdk-go/option. In Go, a value in PARTITE_API_KEY is used before the function, so leave the variable unset when you pass a function.
The CLI reads the same token from PARTITE_API_TOKEN. To the CLI, PARTITE_API_KEY is the key ID of an older form, which needs PARTITE_API_SECRET. If you use both, set PARTITE_API_TOKEN for the CLI.
The token is one of these:
- An API key token. The key needs the scope Converse with meshes. See API Keys.
- A token from an access point. Set the base URL to the access point URL, which the access point’s page shows under Access point URL, such as
https://api.partite.ai/access-points/<ACCESS_POINT_ID>. Pass the caller’s token. These tokens expire, so pass a function that returns the current one.
Base URL
The SDKs call the hosted service at https://api.partite.ai. To call a self-hosted Partite Mesh, or an access point, set the base URL:
| Go | TypeScript |
|---|---|
client.NewClient(option.WithBaseURL("http://localhost:8080")) | new PartiteAiClient({ baseUrl: "http://localhost:8080" }) |
A self-hosted server that does not require auth takes calls without a token. One with REQUIRE_AUTH=true takes API keys: with cloud config, the hosted service’s keys, and with local config, keys created on that server.
Related
- Conversation API: what each call does.
- Conversation API reference: every operation and field.
- Client tasks and AG-UI: answering tasks.
- CLI: run meshes from the terminal.