litellmmigrate

package
v0.1.100 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package litellmmigrate converts a LiteLLM proxy config.yaml into an equivalent GoModel config.yaml, the environment variables it needs, and a report of everything that was changed, approximated, or left behind.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplyResult

type ApplyResult struct {
	Policies   int
	Budgets    int
	RateLimits int
	// Keys counts newly imported keys, KeysUpdated earlier imports brought up
	// to date (including deactivations).
	Keys        int
	KeysUpdated int
	// Failures describes each write GoModel rejected.
	Failures []string
}

ApplyResult counts what an import wrote to GoModel.

func Apply

func Apply(ctx context.Context, client *http.Client, baseURL, adminKey string, plan *ImportPlan) (ApplyResult, error)

Apply writes plan to the GoModel admin API at baseURL, authenticating with adminKey. Policies, budgets, and rate limits go first, and a key whose path or an ancestor's rule was rejected is held back, so no key is ever less restricted than in LiteLLM. Every write is an upsert, so Apply can be re-run. It first checks that adminKey is a global admin credential and that GoModel has every feature the plan needs, and fails without writing anything if not; after that, a rejected write is recorded and the rest continue.

type BudgetImport

type BudgetImport struct {
	UserPath      string
	Period        string
	PeriodSeconds int64
	Amount        float64
	// Spend is what LiteLLM counted in its current period. GoModel starts the
	// period from its own usage records.
	Spend float64
}

BudgetImport is a spend limit on a user path (PUT /admin/budgets).

type Database

type Database struct {
	Keys          []dbKey
	Teams         []dbTeam
	Users         []dbUser
	Organizations []dbOrganization
	Budgets       []dbBudget
}

Database holds the LiteLLM proxy objects the import reads: virtual keys, teams, users, organizations, and the budget rows they reference.

func ReadDatabase

func ReadDatabase(ctx context.Context, url string) (*Database, error)

ReadDatabase reads the LiteLLM objects from the PostgreSQL database at url inside a read-only transaction. Each row is read as JSON, so columns a LiteLLM version lacks are simply unset, and a missing table reads as empty.

type Finding

type Finding struct {
	Severity Severity
	Subject  string
	Message  string
}

Finding is one report entry about a LiteLLM setting.

type ImportPlan

type ImportPlan struct {
	Policies   []PolicyImport
	Budgets    []BudgetImport
	RateLimits []RateLimitImport
	Keys       []KeyImport
	// DisabledKeys counts keys that are blocked, expired, or in a blocked
	// team. They are sent disabled, so an earlier import is deactivated.
	DisabledKeys int
}

ImportPlan lists what the database import creates in GoModel, in the order it is applied: model policies first, so no imported key is ever briefly less restricted than it was in LiteLLM.

func PlanImport

func PlanImport(db *Database, result *Result, now time.Time) *ImportPlan

PlanImport maps the LiteLLM database onto GoModel user paths, model policies, budgets, rate limits, and imported keys, and records what does not carry over in result's report. Model names resolve through the virtual models the config conversion produced.

type KeyImport

type KeyImport struct {
	Name          string     `json:"name"`
	ImportedFrom  string     `json:"imported_from"`
	SecretHash    string     `json:"secret_hash"`
	RedactedValue string     `json:"redacted_value,omitempty"`
	UserPath      string     `json:"user_path"`
	Labels        []string   `json:"labels,omitempty"`
	AllowedModels []string   `json:"allowed_models,omitempty"`
	ExpiresAt     *time.Time `json:"expires_at,omitempty"`
	// Enabled is false for a key LiteLLM blocked or expired.
	Enabled *bool `json:"enabled,omitempty"`
}

KeyImport is one LiteLLM virtual key (POST /admin/auth-keys/import).

type PolicyImport

type PolicyImport struct {
	UserPath      string   `json:"user_path"`
	AllowedModels []string `json:"allowed_models"`
	Description   string   `json:"description,omitempty"`
}

PolicyImport is a user-path model allowlist (PUT /admin/users).

type RateLimitImport

type RateLimitImport struct {
	UserPath    string
	Period      string
	MaxRequests *int64
	MaxTokens   *int64
}

RateLimitImport is a rate limit rule on a user path (PUT /admin/rate-limits).

type Report

type Report struct {
	Source        string
	Deployments   int
	Providers     []providerRow
	VirtualModels []virtualModelOut
	// RequiredEnv lists variables the LiteLLM config read from the
	// environment; GoModel needs them too.
	RequiredEnv []string
	// WrittenEnv lists variables written to the generated .env file.
	WrittenEnv []string
	Findings   []Finding
	// Import is the plan read from the LiteLLM database, nil when the
	// database was not read.
	Import *ImportPlan
}

Report describes what a conversion produced and what it left behind.

func (*Report) Count

func (r *Report) Count(severity Severity) int

Count returns the number of findings with the given severity.

func (*Report) Markdown

func (r *Report) Markdown() string

Markdown renders the report for MIGRATION_REPORT.md and the dry-run output.

type Result

type Result struct {
	// Config is the GoModel config.yaml.
	Config []byte
	// Env is the .env file holding values that were inline in the LiteLLM
	// config. It is nil when there are none.
	Env []byte
	// Report lists what was converted, changed, and left behind.
	Report *Report
	// DatabaseURL is general_settings.database_url with any os.environ/
	// reference resolved, or "" when the config sets none.
	DatabaseURL string
	// MasterKey is general_settings.master_key resolved the same way. It is
	// the admin key of the migrated GoModel.
	MasterKey string
}

Result is the outcome of converting one LiteLLM config.

func ConvertFile

func ConvertFile(path string) (*Result, error)

ConvertFile converts the LiteLLM proxy config at path, following its include: directives.

type Severity

type Severity string

Severity classifies a report finding.

const (
	// SeverityInfo marks a setting that was converted with a behavior change
	// worth knowing about.
	SeverityInfo Severity = "info"
	// SeverityWarning marks something the operator must review or finish.
	SeverityWarning Severity = "warning"
	// SeveritySkipped marks a setting that was not migrated.
	SeveritySkipped Severity = "skipped"
)

Jump to

Keyboard shortcuts

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