Model tiers: per-model credits and premium/vip roles
LLM_MODELS entries are now model[=credits][@role]. The default tiers follow the model comparison rated by an astrologer: Claude Haiku 5.5 (free, 1 credit), GPT-5.6 Terra (premium, 3 credits), Claude Opus 5.5 (vip, 10 credits). VIP includes premium, admins may use every model. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -123,7 +123,7 @@ pub async fn credits(State(state): St, auth: AuthUser) -> ApiResult<Json<Value>>
|
||||
Ok(Json(json!({
|
||||
"balance": balance,
|
||||
"monthly_free_credits": state.config.monthly_free_credits,
|
||||
"analysis_cost": state.config.analysis_cost,
|
||||
"llm_models": state.config.llm_models,
|
||||
"period": credits::current_period(),
|
||||
"ledger": ledger.into_iter().map(|(id, delta, reason, period, analysis_id, note, at)| json!({
|
||||
"id": id, "delta": delta, "reason": reason, "period": period,
|
||||
|
||||
@@ -114,13 +114,20 @@ async fn request(
|
||||
req: AnalysisRequest,
|
||||
) -> ApiResult<(StatusCode, Json<Value>)> {
|
||||
let language = validate_locale(state, Some(req.language.as_deref().unwrap_or(&auth.user.locale)))?;
|
||||
let model = req.model.unwrap_or_else(|| state.config.llm_models[0].clone());
|
||||
if !state.config.llm_models.contains(&model) {
|
||||
return Err(ApiError::BadRequest(format!(
|
||||
"unknown model '{model}'; available: {}",
|
||||
state.config.llm_models.join(", ")
|
||||
)));
|
||||
let models = &state.config.llm_models;
|
||||
let chosen = match &req.model {
|
||||
None => &models[0],
|
||||
Some(id) => models.iter().find(|m| &m.id == id).ok_or_else(|| {
|
||||
let available: Vec<&str> = models.iter().map(|m| m.id.as_str()).collect();
|
||||
ApiError::BadRequest(format!("unknown model '{id}'; available: {}", available.join(", ")))
|
||||
})?,
|
||||
};
|
||||
if let Some(role) = chosen.role
|
||||
&& !auth.user.has_access(role)
|
||||
{
|
||||
return Err(ApiError::Forbidden(format!("the model '{}' needs the '{}' role", chosen.id, role.as_str())));
|
||||
}
|
||||
let model = chosen.id.clone();
|
||||
let (kind, hash, chart_id, synastry_id) = match &target {
|
||||
Target::Natal { chart_id, hash } => ("natal", hash, Some(*chart_id), None),
|
||||
Target::Synastry { synastry_id, hash } => ("synastry", hash, None, Some(*synastry_id)),
|
||||
@@ -180,7 +187,7 @@ async fn request(
|
||||
}
|
||||
|
||||
// New analysis: spend credits and queue it for the worker.
|
||||
let cost = state.config.analysis_cost;
|
||||
let cost = chosen.credits;
|
||||
let mut tx = state.db.begin().await?;
|
||||
let row: AnalysisRow = sqlx::query_as(&insert)
|
||||
.bind(id)
|
||||
|
||||
@@ -116,7 +116,7 @@ async fn public_config(State(state): St) -> Json<Value> {
|
||||
"google_login": { "enabled": state.google.enabled(), "client_id": c.google_client_ids.first() },
|
||||
"locales": c.supported_locales,
|
||||
"llm_models": c.llm_models,
|
||||
"analysis_cost": c.analysis_cost,
|
||||
"default_model": c.llm_models[0].id,
|
||||
"monthly_free_credits": c.monthly_free_credits,
|
||||
"password_min_length": crate::auth::MIN_PASSWORD_LEN,
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user