Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(models): add new `REQUESTS` unit (#2651)

Marc Klingen2291ac662567
diff --git a/fern/apis/server/definition/commons.yml b/fern/apis/server/definition/commons.yml
index a7983a2914..8868e89469 100644
--- a/fern/apis/server/definition/commons.yml
+++ b/fern/apis/server/definition/commons.yml
@@ -292,6 +292,7 @@ types:
- MILLISECONDS
- SECONDS
- IMAGES
+ - REQUESTS
ObservationLevel:
enum:
- DEBUG
diff --git a/packages/shared/prisma/schema.prisma b/packages/shared/prisma/schema.prisma
index 21680a0a5d..b83e13fae6 100644
--- a/packages/shared/prisma/schema.prisma
+++ b/packages/shared/prisma/schema.prisma
@@ -632,7 +632,7 @@ model Model {
inputPrice Decimal? @map("input_price")
outputPrice Decimal? @map("output_price")
totalPrice Decimal? @map("total_price")
- unit String // TOKENS, CHARACTERS, MILLISECONDS, SECONDS, or IMAGES
+ unit String // TOKENS, CHARACTERS, MILLISECONDS, SECONDS, REQUESTS, or IMAGES
tokenizerId String? @map("tokenizer_id")
tokenizerConfig Json? @map("tokenizer_config")
diff --git a/packages/shared/src/constants.ts b/packages/shared/src/constants.ts
index 6e90039201..0f39133635 100644
--- a/packages/shared/src/constants.ts
+++ b/packages/shared/src/constants.ts
@@ -6,4 +6,5 @@ export enum ModelUsageUnit {
Seconds = "SECONDS",
Milliseconds = "MILLISECONDS",
Images = "IMAGES",
+ Requests = "REQUESTS",
}
diff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.yml
index d434ee0ee3..9a52a5b8c3 100644
--- a/web/public/generated/api/openapi.yml
+++ b/web/public/generated/api/openapi.yml
@@ -2650,6 +2650,7 @@ components:
- MILLISECONDS
- SECONDS
- IMAGES
+ - REQUESTS
description: Unit of usage in Langfuse
ObservationLevel:
title: ObservationLevel
diff --git a/web/src/__tests__/ingestion.servertest.ts b/web/src/__tests__/ingestion.servertest.ts
index 8afd957d8e..57038744c2 100644
--- a/web/src/__tests__/ingestion.servertest.ts
+++ b/web/src/__tests__/ingestion.servertest.ts
@@ -57,6 +57,17 @@ describe("/api/public/ingestion API Endpoint", () => {
expectedCompletionTokens: 2,
expectedTotalTokens: 3,
},
+ {
+ usage: {
+ input: 1,
+ output: 2,
+ unit: ModelUsageUnit.Requests,
+ },
+ expectedUnit: ModelUsageUnit.Requests,
+ expectedPromptTokens: 1,
+ expectedCompletionTokens: 2,
+ expectedTotalTokens: 3,
+ },
{
usage: {
input: 30,
diff --git a/web/src/components/table/use-cases/models.tsx b/web/src/components/table/use-cases/models.tsx
index 3e3da71d51..491cd6082a 100644
--- a/web/src/components/table/use-cases/models.tsx
+++ b/web/src/components/table/use-cases/models.tsx
@@ -43,7 +43,7 @@ const modelConfigDescriptions = {
outputPrice: "Price per 1000 units of output",
totalPrice:
"Price per 1000 units, for models that don't have input/output specific prices",
- unit: "Unit of measurement for generative model, can be TOKENS, CHARACTERS, SECONDS, MILLISECONDS, or IMAGES.",
+ unit: "Unit of measurement for generative model, can be TOKENS, CHARACTERS, SECONDS, MILLISECONDS, REQUESTS or IMAGES.",
tokenizerId:
"Tokenizer used for this model to calculate token counts if none are ingested. Pick from list of supported tokenizers.",
config:
diff --git a/web/src/features/public-api/types/models.ts b/web/src/features/public-api/types/models.ts
index 7e36ab367b..76875d04b5 100644
--- a/web/src/features/public-api/types/models.ts
+++ b/web/src/features/public-api/types/models.ts
@@ -1,5 +1,5 @@
import {
- type ModelUsageUnit,
+ type ModelUsageUnit as PrismaModelUsageUnit,
paginationMetaResponseZod,
paginationZod,
type Model as PrismaModel,
@@ -11,7 +11,16 @@ import { z } from "zod";
* Objects
*/
-const ModelDefinition = z
+const APIModelUsageUnit = z.enum([
+ "TOKENS",
+ "CHARACTERS",
+ "MILLISECONDS",
+ "SECONDS",
+ "REQUESTS",
+ "IMAGES",
+]);
+
+const APIModelDefinition = z
.object({
id: z.string(),
modelName: z.string(),
@@ -20,7 +29,7 @@ const ModelDefinition = z
inputPrice: z.number().nonnegative().nullable(),
outputPrice: z.number().nonnegative().nullable(),
totalPrice: z.number().nonnegative().nullable(),
- unit: z.enum(["TOKENS", "CHARACTERS", "MILLISECONDS", "SECONDS", "IMAGES"]),
+ unit: APIModelUsageUnit,
tokenizerId: z.string().nullable(),
tokenizerConfig: z.any(), // Assuming Prisma.JsonValue is any type
isLangfuseManaged: z.boolean(),
@@ -41,10 +50,10 @@ export function prismaToApiModelDefinition({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
updatedAt,
...model
-}: PrismaModel): z.infer<typeof ModelDefinition> {
+}: PrismaModel): z.infer<typeof APIModelDefinition> {
return {
...model,
- unit: unit as ModelUsageUnit,
+ unit: unit as PrismaModelUsageUnit,
inputPrice: inputPrice?.toNumber() ?? null,
outputPrice: outputPrice?.toNumber() ?? null,
totalPrice: totalPrice?.toNumber() ?? null,
@@ -62,7 +71,7 @@ export const GetModelsV1Query = z.object({
});
export const GetModelsV1Response = z
.object({
- data: z.array(ModelDefinition),
+ data: z.array(APIModelDefinition),
meta: paginationMetaResponseZod,
})
.strict();
@@ -76,7 +85,7 @@ export const PostModelsV1Body = z
inputPrice: z.number().nonnegative().nullish(),
outputPrice: z.number().nonnegative().nullish(),
totalPrice: z.number().nonnegative().nullish(),
- unit: z.enum(["TOKENS", "CHARACTERS", "MILLISECONDS", "SECONDS", "IMAGES"]),
+ unit: APIModelUsageUnit,
tokenizerId: z.enum(["openai", "claude"]).nullish(),
tokenizerConfig: jsonSchema.nullish(), // Assuming Prisma.JsonValue is any type
})
@@ -92,13 +101,13 @@ export const PostModelsV1Body = z
message: "If input and/or output price is set, total price must be null",
},
);
-export const PostModelsV1Response = ModelDefinition.strict();
+export const PostModelsV1Response = APIModelDefinition.strict();
// GET /models/{modelId}
export const GetModelV1Query = z.object({
modelId: z.string(),
});
-export const GetModelV1Response = ModelDefinition.strict();
+export const GetModelV1Response = APIModelDefinition.strict();
// DELETE /models/{modelId}
export const DeleteModelV1Query = z.object({