xiaomi

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package xiaomi resolves Xiaomi MiMo API base URLs for pay-as-you-go and Token Plan.

Index

Constants

View Source
const (
	PayAsYouGoOpenAIBase      = "https://api.xiaomimimo.com/v1"
	PayAsYouGoAnthropicBase   = "https://api.xiaomimimo.com/anthropic"
	TokenPlanCNOpenAIBase     = "https://token-plan-cn.xiaomimimo.com/v1"
	TokenPlanCNAnthropicBase  = "https://token-plan-cn.xiaomimimo.com/anthropic"
	TokenPlanSGPOpenAIBase    = "https://token-plan-sgp.xiaomimimo.com/v1"
	TokenPlanSGPAnthropicBase = "https://token-plan-sgp.xiaomimimo.com/anthropic"
	TokenPlanAMSOpenAIBase    = "https://token-plan-ams.xiaomimimo.com/v1"
	TokenPlanAMSAnthropicBase = "https://token-plan-ams.xiaomimimo.com/anthropic"
)
View Source
const DefaultPlatformModelsURL = "https://platform.xiaomimimo.com/api/v1/models"

DefaultPlatformModelsURL is the public MiMo platform catalog (context, pricing, names). Inference GET {base}/models only returns id/object/owned_by.

View Source
const ProviderPayAsYouGo = "xiaomi_mimo_payg"

ProviderPayAsYouGo is the registry / setup gateway id for pay-as-you-go.

View Source
const ProviderTokenPlan = "xiaomi_mimo_token_plan"

ProviderTokenPlan is the registry / setup gateway id for Token Plan.

Variables

This section is empty.

Functions

func AppendKeyMismatchHint

func AppendKeyMismatchHint(err error, providerID, secret string) error

AppendKeyMismatchHint adds a billing/key-shape hint to probe or setup errors (never blocks save).

func ApplyPlatformMetadata

func ApplyPlatformMetadata(
	id, displayName, description string,
	ctx, maxOut int,
	inPrice, outPrice float64,
	inferenceRaw json.RawMessage,
	platform map[string]PlatformModel,
) (string, string, int, int, float64, float64, json.RawMessage)

ApplyPlatformMetadata fills empty live fields from platform catalog; stores platform JSON as metadata when matched.

func FetchOpenAIModelsJSON

func FetchOpenAIModelsJSON(ctx context.Context, baseURL, apiKey string) ([]json.RawMessage, error)

FetchOpenAIModelsJSON GETs /models and returns raw model objects from the OpenAI list response.

func FetchPlatformModelsIndex

func FetchPlatformModelsIndex(ctx context.Context, catalogURL string) (map[string]PlatformModel, error)

FetchPlatformModelsIndex GETs the platform catalog and indexes by native model id.

func IsRetryableHTTPStatus

func IsRetryableHTTPStatus(status int) bool

IsRetryableHTTPStatus reports whether chat may retry via Anthropic compatibility.

func KeyMismatchHint

func KeyMismatchHint(billing Billing, secret string) string

KeyMismatchHint returns a user-facing hint when key shape may not match billing (never blocks save).

func NativeModelID

func NativeModelID(id string) string

NativeModelID strips vendor prefix (xiaomi/mimo-v2.5 → mimo-v2.5).

func PlatformModelsURLFromEnv

func PlatformModelsURLFromEnv(env map[string]string) string

PlatformModelsURLFromEnv returns override URL for tests, else DefaultPlatformModelsURL.

func ProbeOpenAIModels

func ProbeOpenAIModels(ctx context.Context, baseURL, apiKey string) error

ProbeOpenAIModels GETs {baseURL}/models using api-key auth, then Bearer on 401.

func ResolveAnthropicBase

func ResolveAnthropicBase(billing Billing, region Region) (string, error)

ResolveAnthropicBase returns the Anthropic-compatible base URL (no /v1 suffix).

func ResolveOpenAIBase

func ResolveOpenAIBase(billing Billing, region Region, override string) (string, error)

ResolveOpenAIBase returns the OpenAI-compatible base URL (with /v1 suffix).

func ResolveOpenAIBasePreferRegion

func ResolveOpenAIBasePreferRegion(billing Billing, region Region, override string) (string, error)

ResolveOpenAIBasePreferRegion returns the OpenAI base URL. For Token Plan, a valid region wins over a stale persisted override (e.g. user switched cn → sgp but base URL was not cleared).

func SetMimoRequestAuth

func SetMimoRequestAuth(req *http.Request, apiKey string)

SetMimoRequestAuth applies MiMo-preferred auth (api-key header).

Types

type Billing

type Billing string

Billing identifies pay-as-you-go vs Token Plan products (independent keys and hosts).

const (
	BillingPayAsYouGo Billing = "payg"
	BillingTokenPlan  Billing = "token_plan"
)

func BillingForProvider

func BillingForProvider(providerID string) (Billing, bool)

BillingForProvider maps registry provider ids to billing mode.

type PlatformModel

type PlatformModel struct {
	ID               string
	Name             string
	Description      string
	ContextLength    int
	MaxOutputLength  int
	InputPricePer1M  float64
	OutputPricePer1M float64
	Raw              json.RawMessage
}

PlatformModel is one row from the platform catalog API.

type Region

type Region string

Region is a Token Plan cluster (required for token_plan billing).

const (
	RegionCN  Region = "cn"
	RegionSGP Region = "sgp"
	RegionAMS Region = "ams"
)

func NormalizeRegion

func NormalizeRegion(region string) (Region, error)

NormalizeRegion parses a region id (cn, sgp, ams).

Jump to

Keyboard shortcuts

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