Skip to content

Go SDK

The Connix Go SDK provides a robust and type-safe way to integrate Connix services into your Go applications. Built with performance and developer experience in mind, it offers idiomatic Go interfaces for all Connix platform features.

Install the Connix Go SDK using Go modules:

Terminal window
go get github.com/connix-io/connix-go

Before using the SDK, you’ll need an API key from the Connix Console:

package main
import (
"context"
"log"
connix "github.com/connix-io/connix-go"
)
func main() {
// Initialize client with API key
client := connix.NewClient("your-api-key-here")
// Or use environment variable CONNIX_API_KEY
client := connix.NewClientFromEnv()
}

Projects are the primary organizational unit in Connix. Here’s how to create and manage them:

ctx := context.Background()
// Create a new project
project, err := client.CreateProject(ctx, &connix.CreateProjectRequest{
Name: "my-ai-project",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Created project: %s (ID: %d)\n", project.Name, project.Id)
// List all projects
projects, err := client.ListProjects(ctx)
if err != nil {
log.Fatal(err)
}
for _, p := range projects.Projects {
fmt.Printf("Project: %s (ID: %d)\n", p.Name, p.Id)
}

Deploy AI agents to your Connix environment:

// Launch an agent within a project
agent, err := client.LaunchAgent(ctx, &connix.LaunchAgentRequest{
Name: "code-assistant",
ProjectId: project.Id,
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Agent launched: %s\n", agent.Message)

Customize the client behavior with configuration options:

import "time"
client := connix.NewClient(
"your-api-key",
connix.WithBaseURL("https://api.connix.io"),
connix.WithTimeout(30*time.Second),
connix.WithRetries(3),
connix.WithUserAgent("MyApp/1.0"),
)

The SDK provides structured error handling with detailed error information:

project, err := client.CreateProject(ctx, req)
if err != nil {
var connixErr *connix.APIError
if errors.As(err, &connixErr) {
switch connixErr.StatusCode {
case 401:
log.Fatal("Invalid API key")
case 429:
log.Printf("Rate limited, retry after: %s", connixErr.RetryAfter)
default:
log.Printf("API error: %s (code: %d)", connixErr.Message, connixErr.StatusCode)
}
} else {
log.Printf("Network or other error: %v", err)
}
return
}

Here’s a complete example that demonstrates the typical workflow:

package main
import (
"context"
"fmt"
"log"
connix "github.com/connix-io/connix-go"
)
func main() {
// Initialize client
client := connix.NewClientFromEnv()
ctx := context.Background()
// Create a project
project, err := client.CreateProject(ctx, &connix.CreateProjectRequest{
Name: "ml-training-pipeline",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("✅ Created project: %s\n", project.Name)
// Launch an agent for the project
agent, err := client.LaunchAgent(ctx, &connix.LaunchAgentRequest{
Name: "data-processor",
ProjectId: project.Id,
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("🚀 Launched agent: %s\n", agent.Message)
// List all projects to verify
projects, err := client.ListProjects(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Printf("📋 Total projects: %d\n", len(projects.Projects))
}
  • CreateProject(ctx context.Context, req *CreateProjectRequest) (*Project, error)
  • ListProjects(ctx context.Context) (*ListProjectsResponse, error)
  • LaunchAgent(ctx context.Context, req *LaunchAgentRequest) (*LaunchAgentResponse, error)
  • Hello(ctx context.Context, name string) (*HelloResponse, error)
  • WithBaseURL(url string) - Set custom API base URL
  • WithTimeout(duration time.Duration) - Set request timeout
  • WithRetries(count int) - Set retry attempts for failed requests
  • WithUserAgent(ua string) - Set custom User-Agent header
type Project struct {
Id int32 `json:"id"`
Name string `json:"name"`
}
type CreateProjectRequest struct {
Name string `json:"name"`
}
type LaunchAgentRequest struct {
Name string `json:"name"`
ProjectId int32 `json:"project_id"`
}

For more comprehensive examples, visit our examples repository which includes:

  • Multi-agent workflows
  • Integration with popular Go frameworks
  • Error handling patterns
  • Production deployment examples