π Complete Go library for integration with Manus AI API. Easily integrate Manus AI agent into your Go applications.
π Language: English | Π ΡΡΡΠΊΠΈΠΉ
- Features
- Requirements
- Installation
- Configuration
- Usage
- API Reference
- Examples
- Testing
- Contributing
- License
- β Full support for Manus AI API
- β Task creation and management
- β File upload and attachment handling
- β Webhook integration for real-time updates
- β Comprehensive error handling with custom error types
- β Type-safe interfaces
- β Full test coverage
- β Detailed documentation and examples
- β Idiomatic Go code
- Go 1.21 or higher
Install the package using go get:
go get github.com/tigusigalpa/manus-ai-go- Sign up at Manus AI
- Get your API key from the API Integration settings
import manusai "github.com/tigusigalpa/manus-ai-go"
client, err := manusai.NewClient("your-api-key-here")
if err != nil {
log.Fatal(err)
}import (
"time"
manusai "github.com/tigusigalpa/manus-ai-go"
)
client, err := manusai.NewClient(
"your-api-key",
manusai.WithBaseURL("https://custom.api.com"),
manusai.WithTimeout(60 * time.Second),
)package main
import (
"fmt"
"log"
manusai "github.com/tigusigalpa/manus-ai-go"
)
func main() {
client, err := manusai.NewClient("your-api-key")
if err != nil {
log.Fatal(err)
}
// Create a task
task, err := client.CreateTask("Write a poem about Go programming", &manusai.TaskOptions{
AgentProfile: manusai.AgentProfileManus16,
TaskMode: "chat",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Task created: %s\n", task.TaskID)
fmt.Printf("View at: %s\n", task.TaskURL)
}Tasks are the core of Manus AI - they represent AI agent work items that can perform complex operations, answer questions, or automate workflows.
API Documentation: Tasks API Reference
task, err := client.CreateTask("Your task prompt here", &manusai.TaskOptions{
AgentProfile: manusai.AgentProfileManus16,
TaskMode: "agent", // "chat", "adaptive", or "agent"
Locale: "en-US",
HideInTaskList: &falseVal,
CreateShareableLink: &trueVal,
})
if err != nil {
log.Fatal(err)
}Available Agent Profiles:
AgentProfileManus16- Latest and most capable model (recommended)AgentProfileManus16Lite- Faster, lightweight versionAgentProfileManus16Max- Maximum capability versionAgentProfileSpeed-β οΈ Deprecated, useAgentProfileManus16LiteinsteadAgentProfileQuality-β οΈ Deprecated, useAgentProfileManus16instead
// Check if a profile is valid
if manusai.IsValidAgentProfile("manus-1.6") {
fmt.Println("Valid profile")
}
// Check if deprecated
if manusai.IsDeprecatedAgentProfile(manusai.AgentProfileSpeed) {
fmt.Println("This profile is deprecated")
}
// Get all recommended profiles
profiles := manusai.RecommendedAgentProfiles()task, err := client.GetTask("task_id")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Status: %s\n", task.Status)
fmt.Printf("Credits used: %.2f\n", task.CreditUsage)
// Access output messages
for _, message := range task.Output {
fmt.Printf("[%s]: %s\n", message.Role, message.Content)
}tasks, err := client.GetTasks(&manusai.TaskFilters{
Limit: 10,
Order: "desc",
OrderBy: "created_at",
Status: []string{"completed", "running"},
})
if err != nil {
log.Fatal(err)
}
for _, task := range tasks.Data {
fmt.Printf("Task %s: %s\n", task.ID, task.Status)
}newTitle := "New Task Title"
enableShared := true
updated, err := client.UpdateTask("task_id", &manusai.TaskUpdate{
Title: &newTitle,
EnableShared: &enableShared,
EnableVisibleInTaskList: &enableShared,
})
if err != nil {
log.Fatal(err)
}result, err := client.DeleteTask("task_id")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Deleted: %v\n", result.Deleted)Manus AI supports file attachments to provide context for your tasks. The file upload process uses a two-step approach: first, create a file record to get a secure presigned URL, then upload your content directly to cloud storage.
API Documentation: Files API Reference
// 1. Create file record
fileResult, err := client.CreateFile("document.pdf")
if err != nil {
log.Fatal(err)
}
// 2. Upload file content
fileContent, _ := os.ReadFile("/path/to/document.pdf")
err = client.UploadFileContent(
fileResult.UploadURL,
fileContent,
"application/pdf",
)
if err != nil {
log.Fatal(err)
}
// 3. Use file in task
attachment := manusai.NewAttachmentFromFileID(fileResult.ID)
task, err := client.CreateTask("Analyze this document", &manusai.TaskOptions{
Attachments: []interface{}{attachment},
})// From file ID
attachment1 := manusai.NewAttachmentFromFileID("file_123")
// From URL
attachment2 := manusai.NewAttachmentFromURL("https://example.com/image.jpg")
// From base64
attachment3 := manusai.NewAttachmentFromBase64(base64Data, "image/png")
// From local file path
attachment4, err := manusai.NewAttachmentFromFilePath("/path/to/file.pdf")
if err != nil {
log.Fatal(err)
}files, err := client.ListFiles()
if err != nil {
log.Fatal(err)
}
for _, file := range files.Data {
fmt.Printf("%s - %s\n", file.Filename, file.Status)
}result, err := client.DeleteFile("file_id")
if err != nil {
log.Fatal(err)
}Webhooks enable real-time notifications about your task lifecycle events. Instead of polling for updates, Manus AI will send HTTP POST requests to your specified endpoint whenever important events occur.
API Documentation: Webhooks Guide
webhook := &manusai.WebhookConfig{
URL: "https://your-domain.com/webhook/manus-ai",
Events: []string{"task_created", "task_stopped"},
}
result, err := client.CreateWebhook(webhook)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Webhook ID: %s\n", result.WebhookID)import (
"io"
"net/http"
manusai "github.com/tigusigalpa/manus-ai-go"
)
func handleWebhook(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
defer r.Body.Close()
payload, err := manusai.ParseWebhookPayload(body)
if err != nil {
http.Error(w, "Invalid payload", http.StatusBadRequest)
return
}
if manusai.IsTaskCompleted(payload) {
taskDetail := manusai.GetTaskDetail(payload)
attachments := manusai.GetAttachments(payload)
fmt.Printf("Task completed: %v\n", taskDetail["task_id"])
fmt.Printf("Message: %v\n", taskDetail["message"])
// Download attachments
for _, att := range attachments {
if attMap, ok := att.(map[string]interface{}); ok {
fmt.Printf("File: %v\n", attMap["file_name"])
fmt.Printf("URL: %v\n", attMap["url"])
}
}
}
if manusai.IsTaskAskingForInput(payload) {
taskDetail := manusai.GetTaskDetail(payload)
fmt.Printf("Input required: %v\n", taskDetail["message"])
}
w.WriteHeader(http.StatusOK)
}err := client.DeleteWebhook("webhook_id")
if err != nil {
log.Fatal(err)
}CreateTask(prompt string, options *TaskOptions) (*TaskResponse, error)GetTasks(filters *TaskFilters) (*TaskListResponse, error)GetTask(taskID string) (*TaskDetail, error)UpdateTask(taskID string, updates *TaskUpdate) (*TaskDetail, error)DeleteTask(taskID string) (*DeleteResponse, error)
CreateFile(filename string) (*FileResponse, error)UploadFileContent(uploadURL string, fileContent []byte, contentType string) errorListFiles() (*FileListResponse, error)GetFile(fileID string) (*FileDetail, error)DeleteFile(fileID string) (*DeleteResponse, error)
CreateWebhook(webhook *WebhookConfig) (*WebhookResponse, error)DeleteWebhook(webhookID string) error
AllAgentProfiles() []string- Get all available profilesRecommendedAgentProfiles() []string- Get recommended profilesIsValidAgentProfile(profile string) bool- Check if profile is validIsDeprecatedAgentProfile(profile string) bool- Check if profile is deprecated
NewAttachmentFromFileID(fileID string) map[string]interface{}NewAttachmentFromURL(url string) map[string]interface{}NewAttachmentFromBase64(base64Data, mimeType string) map[string]interface{}NewAttachmentFromFilePath(filePath string) (map[string]interface{}, error)
ParseWebhookPayload(jsonPayload []byte) (*WebhookPayload, error)IsTaskCreated(payload *WebhookPayload) boolIsTaskStopped(payload *WebhookPayload) boolIsTaskCompleted(payload *WebhookPayload) boolIsTaskAskingForInput(payload *WebhookPayload) boolGetTaskDetail(payload *WebhookPayload) map[string]interface{}GetAttachments(payload *WebhookPayload) []interface{}
The SDK provides custom error types for better error handling:
ManusAIError- General API errorsAuthenticationError- Authentication/authorization failuresValidationError- Request validation errors
_, err := client.GetTask("invalid_id")
if err != nil {
switch e := err.(type) {
case *manusai.AuthenticationError:
fmt.Println("Authentication failed:", e.Message)
case *manusai.ValidationError:
fmt.Println("Validation error:", e.Message)
case *manusai.ManusAIError:
fmt.Println("API error:", e.Message)
default:
fmt.Println("Unknown error:", err)
}
}See the examples/ directory for complete working examples:
examples/basic/- Basic task creation and managementexamples/file-upload/- File upload with attachmentsexamples/webhook/- Webhook setup and handling
To run an example:
export MANUS_AI_API_KEY=your-api-key
cd examples/basic
go run main.goRun the test suite:
go test -v ./...Run with coverage:
go test -v -cover ./...Generate coverage report:
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.outContributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Igor Sazonov
- GitHub: @tigusigalpa
- Email: [email protected]
- Thanks to the Manus AI team for providing an excellent AI agent platform
- Inspired by the PHP SDK: manus-ai-php
Made with β€οΈ by Igor Sazonov
