Skip to content

LiteLLM API Client ​

The operator communicates with LiteLLM through a REST API client defined as Go interfaces. This enables testing with mock implementations.

Client Interface ​

go
type Client interface {
    Models()        ModelService
    Teams()         TeamService
    Users()         UserService
    Keys()          KeyService
    Organizations() OrganizationService
    Health()        HealthService
}

A ClientFactory function creates clients for each LiteLLM instance:

go
type ClientFactory func(endpoint, masterKey string) Client

Service Interfaces ​

ModelService ​

MethodHTTPEndpointDescription
CreatePOST/model/newRegister a new model
UpdatePOST/model/updateUpdate model configuration
DeletePOST/model/deleteRemove a model
GetGET/model/info?litellm_model_id=Get model info
ListGET/model/infoList all models

TeamService ​

MethodHTTPEndpointDescription
CreatePOST/team/newCreate a team
UpdatePOST/team/updateUpdate team properties
DeletePOST/team/deleteDelete a team
GetGET/team/info?team_id=Get team info
ListGET/team/listList all teams
AddMemberPOST/team/member_addAdd a team member
RemoveMemberPOST/team/member_deleteRemove a team member
ListMembersGET/team/info?team_id=List team members
SetCallbackPOST/team/{team_id}/callbackSet a per-team logging callback (enterprise)
DisableLoggingPOST/team/{team_id}/disable_loggingDisable all logging for a team (enterprise)

UserService ​

MethodHTTPEndpointDescription
CreatePOST/user/newCreate a user
UpdatePOST/user/updateUpdate user properties
DeletePOST/user/deleteDelete a user
GetGET/user/info?user_id=Get user info
ListGET/user/listList all users

KeyService ​

MethodHTTPEndpointDescription
GeneratePOST/key/generateGenerate a virtual key
UpdatePOST/key/updateUpdate key properties
DeletePOST/key/deleteRevoke a key
GetGET/key/info?key=Get key info
ListGET/key/listList all keys

OrganizationService ​

MethodHTTPEndpointDescription
CreatePOST/organization/newCreate an organization
UpdatePOST/organization/updateUpdate organization properties
DeletePOST/organization/deleteDelete an organization
GetGET/organization/info?organization_id=Get organization info
ListGET/organization/listList all organizations
AddMemberPOST/organization/member_addAdd an organization member
DeleteMemberPOST/organization/member_deleteRemove an organization member

HealthService ​

MethodHTTPEndpointDescription
CheckLivenessGET/health/livelinessLiveness check
CheckReadinessGET/health/readinessReadiness check

Authentication ​

All API requests include the master key as a Bearer token:

Authorization: Bearer <master_key>

Error Handling ​

API errors are wrapped in an APIError type:

go
type APIError struct {
    StatusCode int
    Message    string
    Path       string
}

Helper methods:

  • IsNotFound() — returns true for 404 responses
  • IsTransient() — returns true for 5xx responses (triggers requeue)

Mock Client ​

For testing, use litellm.NewMockClient():

go
mock := litellm.NewMockClient()

// Configure custom behavior
mock.MockModels.CreateFunc = func(ctx context.Context, req ModelCreateRequest) (*ModelCreateResponse, error) {
    return &ModelCreateResponse{ModelID: "custom-id"}, nil
}

// Use in controller tests
reconciler := &LiteLLMModelReconciler{
    LiteLLMClientFactory: func(endpoint, masterKey string) litellm.Client {
        return mock
    },
}

Released under the Apache 2.0 License.