aiozai

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2026 License: MIT Imports: 15 Imported by: 0

README

AIOZ AI Go Client

Go client SDK for the AIOZ AI API. Auto-generated from the OpenAPI specification with full type safety.

Features

  • Full type safety for all 218+ API endpoints and 578+ models
  • API Key configured once at client creation
  • Automatic retry with exponential backoff for transient failures
  • Configurable timeouts for standard and upload operations
  • Domain-grouped service access (Models, Datasets, Competitions, etc.)
  • Zero external HTTP dependencies beyond the Go standard library

Installation

go get github.com/AIOZNetwork/aioz-ai-go-client@latest

Requires Go 1.22 or later.

Quick Start

package main

import (
    "context"
    "fmt"
    "log"
    "os"

    aiozai "github.com/AIOZNetwork/aioz-ai-go-client"
)

func main() {
    client, err := aiozai.NewClient(
        aiozai.WithAPIKey(os.Getenv("AIOZ_AI_API_KEY")),
    )
    if err != nil {
        log.Fatal(err)
    }

    ctx := context.Background()
    models := client.Models()
    _ = models // use models.Model, models.Training, etc.
    fmt.Println("client ready", ctx)
}

Error Handling

import "errors"

var apiErr *aiozai.AiozAPIError
if errors.As(err, &apiErr) {
    fmt.Printf("[%d] %s — %s %s\n", apiErr.StatusCode, apiErr.Message, apiErr.Method, apiErr.Endpoint)
}

Configuration

import "time"

client, err := aiozai.NewClient(
    aiozai.WithAPIKey(os.Getenv("AIOZ_AI_API_KEY")),
    aiozai.WithBaseURL("https://api.aiozai.network/api/v1"),
    aiozai.WithTimeout(60 * time.Second),
    aiozai.WithRetryConfig(&aiozai.RetryConfig{
        MaxRetries: 5,
        BaseDelay:  2 * time.Second,
        MaxDelay:   60 * time.Second,
    }),
)

Service Groups

Service Access Description Reference
Models client.Models() AI model management docs/models.md
Datasets client.Datasets() Dataset management docs/datasets.md
Competitions client.Competitions() Competitions & submissions docs/competitions.md
Collections client.Collections() Curated collections docs/collections.md
Discussions client.Discussions() Discussions & comments docs/discussions.md
Notifications client.Notifications() Notification system docs/notifications.md
Organizations client.Organizations() Organization management docs/organizations.md
Repositories client.Repositories() Repository operations docs/repositories.md
Storage client.Storage() Storage & uploads docs/storage.md
Users client.Users() User management docs/users.md
Core client.Core() Core endpoints, search, offers docs/core.md
Public client.Public() Public endpoints (no auth) docs/public.md

License

Apache-2.0


SDK Usage Guide

Auto-generated from swagger/sdk.json — do not edit this section manually. Re-generate with make guide from the repo root.

Authentication Setup

Initialize the client once with your API key and reuse it across all calls:

import (
    "os"
    aiozai "github.com/AIOZNetwork/aioz-ai-go-client"
)

client, err := aiozai.NewClient(
    aiozai.WithAPIKey(os.Getenv("AIOZ_AI_API_KEY")),
)
if err != nil {
    log.Fatal(err)
}

// Use client.Models(), client.Datasets(), etc.

Obtain your API key from the AIOZ AI dashboard.

Common Response Types

These types appear in error responses across all endpoints.

FailResponse (400 Bad Request)

Field Type Description
message string Human-readable error message
errors array[string] Field-level validation errors

ErrorResponse (500 Internal Server Error)

Field Type Description
message string Internal error message

Documentation

Overview

Package aiozai provides a Go client SDK for the AIOZ AI API.

The SDK is auto-generated from the OpenAPI specification and provides typed access to all 218+ API endpoints with 578+ model definitions.

Quick Start

client, err := aiozai.NewClient(
    aiozai.WithAPIKey(os.Getenv("AIOZ_AI_API_KEY")),
)
if err != nil {
    log.Fatal(err)
}

Features

  • Full type safety for all API endpoints and models
  • API Key configured once at client creation
  • Automatic retry with exponential backoff for transient failures
  • Configurable timeouts for standard and upload operations
  • Domain-grouped service access (Models, Datasets, Competitions, etc.)

Authentication

The SDK uses API Key. Set your API key when creating the client with WithAPIKey(). All api-key/* endpoints automatically include the x-api-key header. Public endpoints (public/*) do not require authentication.

Error Handling

API errors are returned as *AiozAPIError which implements the error interface. Use errors.As() to check for API-specific errors:

var apiErr *aiozai.AiozAPIError
if errors.As(err, &apiErr) {
    log.Printf("API error %d: %s", apiErr.StatusCode, apiErr.Message)
}

Index

Constants

View Source
const (
	// DefaultBaseURL is the default base URL for the AIOZ AI API.
	DefaultBaseURL = "https://api.aiozai.network/api/v1"

	// DefaultTimeout is the default request timeout.
	DefaultTimeout = 30 * time.Second

	// DefaultUploadTimeout is the default timeout for upload operations.
	DefaultUploadTimeout = 300 * time.Second

	// DefaultMaxRetries is the default number of retry attempts.
	DefaultMaxRetries = 3

	// DefaultBaseDelay is the initial delay for exponential backoff.
	DefaultBaseDelay = 1 * time.Second

	// DefaultMaxDelay is the maximum delay between retries.
	DefaultMaxDelay = 30 * time.Second
)

Variables

View Source
var RetryableStatusCodes = []int{500, 502, 503, 504}

RetryableStatusCodes contains HTTP status codes that trigger a retry.

Functions

This section is empty.

Types

type AiozAPIError

type AiozAPIError struct {
	StatusCode int    `json:"statusCode"`
	ErrorCode  string `json:"errorCode"`
	Message    string `json:"message"`
	Endpoint   string `json:"endpoint"`
	Method     string `json:"method"`
	RequestID  string `json:"requestId,omitempty"`
}

AiozAPIError represents a structured error from the AIOZ AI API.

func NewAPIError

func NewAPIError(statusCode int, errorCode, message, endpoint, method, requestID string) *AiozAPIError

NewAPIError creates a new AiozAPIError.

func (*AiozAPIError) Error

func (e *AiozAPIError) Error() string

Error implements the error interface.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the AIOZ AI SDK client.

func NewClient

func NewClient(opts ...Option) (*Client, error)

NewClient creates a new SDK client with the given options.

func (*Client) Collections

func (c *Client) Collections() *services.CollectionsService

Collections returns the collections service for curated collection operations.

func (*Client) Competitions

func (c *Client) Competitions() *services.CompetitionsService

Competitions returns the competitions service for competition operations.

func (*Client) Config

func (c *Client) Config() *ClientConfig

Config returns the resolved client configuration.

func (*Client) Core

func (c *Client) Core() *services.CoreService

Core returns the core service for root endpoints and minor services.

func (*Client) Datasets

func (c *Client) Datasets() *services.DatasetsService

Datasets returns the datasets service for dataset management operations.

func (*Client) Discussions

func (c *Client) Discussions() *services.DiscussionsService

Discussions returns the discussions service for discussion and comment operations.

func (*Client) Models

func (c *Client) Models() *services.ModelsService

Models returns the models service for AI model management operations.

func (*Client) Notifications

func (c *Client) Notifications() *services.NotificationsService

Notifications returns the notifications service.

func (*Client) Organizations

func (c *Client) Organizations() *services.OrganizationsService

Organizations returns the organizations service for org management operations.

func (*Client) Public

func (c *Client) Public() *services.PublicService

Public returns the public service for unauthenticated endpoints.

func (*Client) Raw

func (c *Client) Raw() *apiclient.AiozaiPlatform

Raw returns the underlying go-swagger generated client for direct access.

func (*Client) Repositories

func (c *Client) Repositories() *services.RepositoriesService

Repositories returns the repositories service for repository operations.

func (*Client) Storage

func (c *Client) Storage() *services.StorageService

Storage returns the storage service for upload and storage operations.

func (*Client) Users

func (c *Client) Users() *services.UsersService

Users returns the users service for user management operations.

type ClientConfig

type ClientConfig struct {
	APIKey        string
	BaseURL       string
	Timeout       time.Duration
	UploadTimeout time.Duration
	RetryConfig   *RetryConfig
	HTTPClient    *http.Client
}

ClientConfig holds the resolved configuration for the SDK client.

type Option

type Option func(*ClientConfig)

Option is a functional option for configuring the SDK client.

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets the API key for authenticated endpoints.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL overrides the default API base URL.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets a custom HTTP client for the SDK.

func WithRetryConfig

func WithRetryConfig(rc *RetryConfig) Option

WithRetryConfig overrides the default retry configuration.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the request timeout for standard API calls.

func WithUploadTimeout

func WithUploadTimeout(timeout time.Duration) Option

WithUploadTimeout sets the timeout for upload operations.

type RetryConfig

type RetryConfig struct {
	MaxRetries           int
	BaseDelay            time.Duration
	MaxDelay             time.Duration
	RetryableStatusCodes []int
}

RetryConfig controls the retry behavior of the SDK client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL