Adds a new FeatureType.AiCreditSystem that enables model-based token pricing with per-model markup configuration. Includes the @useautumn/ai-sdk package for Vercel AI SDK integration with automatic token tracking. Co-authored-by: TheUntraceable <73362400+TheUntraceable@users.noreply.github.com>
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { z } from "zod/v4";
|
|
import { FeatureUsageType } from "../featureEnums";
|
|
|
|
export const CreditSchemaItemSchema = z.object({
|
|
metered_feature_id: z.string(),
|
|
feature_amount: z.number().optional(),
|
|
credit_amount: z.number(),
|
|
});
|
|
|
|
export const CreditSystemConfigSchema = z.object({
|
|
schema: z.array(
|
|
z.object({
|
|
metered_feature_id: z.string(),
|
|
credit_amount: z.number(),
|
|
}),
|
|
),
|
|
usage_type: z.nativeEnum(FeatureUsageType),
|
|
});
|
|
|
|
export const ModelMarkupsSchema = z
|
|
.record(
|
|
z.string(), // Represents the model name in "provider/model" format, e.g. "anthropic/claude-2"
|
|
z.object({
|
|
markup: z.number().min(0), // percentage markup, e.g. 20 for 20%
|
|
input_cost: z.number().min(0).optional(), // $/M tokens, required for custom/ models
|
|
output_cost: z.number().min(0).optional(), // $/M tokens, required for custom/ models
|
|
}),
|
|
)
|
|
.nullish();
|
|
|
|
export type CreditSystemConfig = z.infer<typeof CreditSystemConfigSchema>;
|
|
export type CreditSchemaItem = z.infer<typeof CreditSchemaItemSchema>;
|
|
export type ModelMarkups = z.infer<typeof ModelMarkupsSchema>;
|