Skip to content

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

feat: allow optional metadata param on org / project CRUD API (#6524)

Steffen Schmitzb101e7c558a9
diff --git a/fern/apis/organizations/definition/organizations.yml b/fern/apis/organizations/definition/organizations.yml
index 6b28fbb3ae..7092e4bd90 100644
--- a/fern/apis/organizations/definition/organizations.yml
+++ b/fern/apis/organizations/definition/organizations.yml
@@ -24,6 +24,9 @@ service:
body:
properties:
name: string
+ metadata:
+ type: optional<map<string, unknown>>
+ docs: Optional metadata for the organization
response: Organization
errors:
- commons.Error
@@ -53,6 +56,9 @@ service:
body:
properties:
name: string
+ metadata:
+ type: optional<map<string, unknown>>
+ docs: Optional metadata for the organization
response: Organization
errors:
- commons.Error
@@ -128,6 +134,9 @@ types:
id: string
name: string
createdAt: datetime
+ metadata:
+ type: map<string, unknown>
+ docs: Metadata for the organization
DeleteOrganizationResponse:
docs: Response for successful organization deletion
diff --git a/fern/apis/server/definition/projects.yml b/fern/apis/server/definition/projects.yml
index 9489e55f3e..548ffb8f5c 100644
--- a/fern/apis/server/definition/projects.yml
+++ b/fern/apis/server/definition/projects.yml
@@ -21,6 +21,9 @@ service:
body:
properties:
name: string
+ metadata:
+ type: optional<map<string, unknown>>
+ docs: Optional metadata for the project
retention:
type: integer
docs: Number of days to retain data. Must be 0 or at least 7 days. Requires data-retention entitlement for non-zero values. Optional.
@@ -37,6 +40,9 @@ service:
body:
properties:
name: string
+ metadata:
+ type: optional<map<string, unknown>>
+ docs: Optional metadata for the project
retention:
type: integer
docs: Number of days to retain data. Must be 0 or at least 7 days. Requires data-retention entitlement for non-zero values. Optional.
@@ -94,6 +100,9 @@ types:
properties:
id: string
name: string
+ metadata:
+ type: map<string, unknown>
+ docs: Metadata for the project
retentionDays:
type: integer
docs: Number of days to retain data. Null or 0 means no retention. Omitted if no retention is configured.
diff --git a/packages/shared/prisma/generated/types.ts b/packages/shared/prisma/generated/types.ts
index 533f3fc931..f1f44c4dcc 100644
--- a/packages/shared/prisma/generated/types.ts
+++ b/packages/shared/prisma/generated/types.ts
@@ -531,6 +531,7 @@ export type Organization = {
created_at: Generated<Timestamp>;
updated_at: Generated<Timestamp>;
cloud_config: unknown | null;
+ metadata: unknown | null;
};
export type OrganizationMembership = {
id: string;
@@ -564,6 +565,7 @@ export type Project = {
deleted_at: Timestamp | null;
name: string;
retention_days: number | null;
+ metadata: unknown | null;
};
export type ProjectMembership = {
org_membership_id: string;
diff --git a/packages/shared/prisma/migrations/20250420120553_add_organization_and_project_metadata/migration.sql b/packages/shared/prisma/migrations/20250420120553_add_organization_and_project_metadata/migration.sql
new file mode 100644
index 0000000000..5e908a5b7b
--- /dev/null
+++ b/packages/shared/prisma/migrations/20250420120553_add_organization_and_project_metadata/migration.sql
@@ -0,0 +1,5 @@
+-- AlterTable
+ALTER TABLE "organizations" ADD COLUMN "metadata" JSONB;
+
+-- AlterTable
+ALTER TABLE "projects" ADD COLUMN "metadata" JSONB;
diff --git a/packages/shared/prisma/schema.prisma b/packages/shared/prisma/schema.prisma
index 52e0a1ab43..7c434fd3c9 100644
--- a/packages/shared/prisma/schema.prisma
+++ b/packages/shared/prisma/schema.prisma
@@ -105,6 +105,7 @@ model Organization {
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
cloudConfig Json? @map("cloud_config") // Langfuse Cloud, for zod schema see @/src/features/organizations/utils/cloudConfigSchema
+ metadata Json?
organizationMemberships OrganizationMembership[]
projects Project[]
MembershipInvitation MembershipInvitation[]
@@ -121,6 +122,7 @@ model Project {
deletedAt DateTime? @map("deleted_at")
name String
retentionDays Int? @map("retention_days")
+ metadata Json?
projectMembers ProjectMembership[]
organization Organization @relation(fields: [orgId], references: [id], onUpdate: Cascade, onDelete: Cascade)
apiKeys ApiKey[]
diff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.yml
index b660e7da42..1a576a47ff 100644
--- a/web/public/generated/api/openapi.yml
+++ b/web/public/generated/api/openapi.yml
@@ -2256,6 +2256,11 @@ paths:
properties:
name:
type: string
+ metadata:
+ type: object
+ additionalProperties: true
+ nullable: true
+ description: Optional metadata for the project
retention:
type: integer
description: >-
@@ -2320,6 +2325,11 @@ paths:
properties:
name:
type: string
+ metadata:
+ type: object
+ additionalProperties: true
+ nullable: true
+ description: Optional metadata for the project
retention:
type: integer
description: >-
@@ -6282,6 +6292,10 @@ components:
type: string
name:
type: string
+ metadata:
+ type: object
+ additionalProperties: true
+ description: Metadata for the project
retentionDays:
type: integer
description: >-
@@ -6290,6 +6304,7 @@ components:
required:
- id
- name
+ - metadata
- retentionDays
ProjectDeletionResponse:
title: ProjectDeletionResponse
diff --git a/web/public/generated/organizations-api/openapi.yml b/web/public/generated/organizations-api/openapi.yml
index d719b170a8..39c9fde397 100644
--- a/web/public/generated/organizations-api/openapi.yml
+++ b/web/public/generated/organizations-api/openapi.yml
@@ -126,6 +126,11 @@ paths:
properties:
name:
type: string
+ metadata:
+ type: object
+ additionalProperties: true
+ nullable: true
+ description: Optional metadata for the organization
required:
- name
/api/admin/organizations/{organizationId}:
@@ -224,6 +229,11 @@ paths:
properties:
name:
type: string
+ metadata:
+ type: object
+ additionalProperties: true
+ nullable: true
+ description: Optional metadata for the organization
required:
- name
delete:
@@ -441,10 +451,15 @@ components:
createdAt:
type: string
format: date-time
+ metadata:
+ type: object
+ additionalProperties: true
+ description: Metadata for the organization
required:
- id
- name
- createdAt
+ - metadata
DeleteOrganizationResponse:
title: DeleteOrganizationResponse
type: object
diff --git a/web/public/generated/organizations-postman/collection.json b/web/public/generated/organizations-postman/collection.json
index 3f7262c2de..b24fedf2bc 100644
--- a/web/public/generated/organizations-postman/collection.json
+++ b/web/public/generated/organizations-postman/collection.json
@@ -80,7 +80,7 @@
"auth": null,
"body": {
"mode": "raw",
- "raw": "{\n \"name\": \"example\"\n}",
+ "raw": "{\n \"name\": \"example\",\n \"metadata\": {\n \"example\": \"UNKNOWN\"\n }\n}",
"options": {
"raw": {
"language": "json"
@@ -152,7 +152,7 @@
"auth": null,
"body": {
"mode": "raw",
- "raw": "{\n \"name\": \"example\"\n}",
+ "raw": "{\n \"name\": \"example\",\n \"metadata\": {\n \"example\": \"UNKNOWN\"\n }\n}",
"options": {
"raw": {
"language": "json"
diff --git a/web/public/generated/postman/collection.json b/web/public/generated/postman/collection.json
index 0eb74cd4e2..3039e88673 100644
--- a/web/public/generated/postman/collection.json
+++ b/web/public/generated/postman/collection.json
@@ -1723,7 +1723,7 @@
"auth": null,
"body": {
"mode": "raw",
- "raw": "{\n \"name\": \"example\",\n \"retention\": 0\n}",
+ "raw": "{\n \"name\": \"example\",\n \"metadata\": {\n \"example\": \"UNKNOWN\"\n },\n \"retention\": 0\n}",
"options": {
"raw": {
"language": "json"
@@ -1763,7 +1763,7 @@
"auth": null,
"body": {
"mode": "raw",
- "raw": "{\n \"name\": \"example\",\n \"retention\": 0\n}",
+ "raw": "{\n \"name\": \"example\",\n \"metadata\": {\n \"example\": \"UNKNOWN\"\n },\n \"retention\": 0\n}",
"options": {
"raw": {
"language": "json"
diff --git a/web/src/__tests__/async/organizations-api.servertest.ts b/web/src/__tests__/async/organizations-api.servertest.ts
index d6610c9ed4..e13f3440d7 100644
--- a/web/src/__tests__/async/organizations-api.servertest.ts
+++ b/web/src/__tests__/async/organizations-api.servertest.ts
@@ -13,6 +13,7 @@ const OrganizationResponseSchema = z.object({
id: z.string(),
name: z.string(),
createdAt: z.string().datetime(),
+ metadata: z.object({}),
});
// Schema for multiple organizations response
@@ -56,6 +57,7 @@ describe("Admin Organizations API", () => {
describe("POST /api/admin/organizations", () => {
it("should create a new organization with valid admin authentication", async () => {
const uniqueOrgName = `Test Org ${randomUUID().substring(0, 8)}`;
+ const metadata = { tier: "testing", users: 5 };
const response = await makeZodVerifiedAPICall(
OrganizationResponseSchema,
@@ -63,6 +65,7 @@ describe("Admin Organizations API", () => {
"/api/admin/organizations",
{
name: uniqueOrgName,
+ metadata: metadata,
},
`Bearer ${ADMIN_API_KEY}`,
201, // Expected status code is 201 Created
@@ -71,6 +74,7 @@ describe("Admin Organizations API", () => {
expect(response.status).toBe(201);
expect(response.body).toMatchObject({
name: uniqueOrgName,
+ metadata: metadata,
});
expect(response.body.id).toBeDefined();
expect(response.body.createdAt).toBeDefined();
@@ -81,6 +85,38 @@ describe("Admin Organizations API", () => {
});
expect(org).not.toBeNull();
expect(org?.name).toBe(uniqueOrgName);
+ expect(org?.metadata).toEqual(metadata);
+ });
+
+ it("should create a new organization without metadata", async () => {
+ const uniqueOrgName = `Test Org ${randomUUID().substring(0, 8)}`;
+
+ const response = await makeZodVerifiedAPICall(
+ OrganizationResponseSchema,
+ "POST",
+ "/api/admin/organizations",
+ {
+ name: uniqueOrgName,
+ },
+ `Bearer ${ADMIN_API_KEY}`,
+ 201, // Expected status code is 201 Created
+ );
+
+ expect(response.status).toBe(201);
+ expect(response.body).toMatchObject({
+ name: uniqueOrgName,
+ metadata: {},
+ });
+ expect(response.body.id).toBeDefined();
+ expect(response.body.createdAt).toBeDefined();
+
+ // Verify the organization was actually created in the database
+ const org = await prisma.organization.findUnique({
+ where: { id: response.body.id },
+ });
+ expect(org).not.toBeNull();
+ expect(org?.name).toBe(uniqueOrgName);
+ expect(org?.metadata).toBeNull();
});
it("should return 401 when no authorization header is provided", async () => {
@@ -142,7 +178,7 @@ describe("Admin Organizations API", () => {
// Create a test organization to retrieve
const uniqueOrgName = `Test Org ${randomUUID().substring(0, 8)}`;
const org = await prisma.organization.create({
- data: { name: uniqueOrgName },
+ data: { name: uniqueOrgName, metadata: { tier: "testing", users: 5 } },
});
testOrgId = org.id;
});
@@ -175,6 +211,10 @@ describe("Admin Organizations API", () => {
expect(
response.body.organizations.some((org) => org.id === testOrgId),
).toBe(true);
+ expect(
+ response.body.organizations.find((org) => org.id === testOrgId)
+ ?.metadata,
+ ).toEqual({ tier: "testing", users: 5 });
});
it("should return 401 when no authorization header is provided", async () => {
@@ -191,7 +231,7 @@ describe("Admin Organizations API", () => {
// Create a test organization to retrieve
const uniqueOrgName = `Test Org ${randomUUID().substring(0, 8)}`;
const org = await prisma.organization.create({
- data: { name: uniqueOrgName },
+ data: { name: uniqueOrgName, metadata: { tier: "testing", users: 5 } },
});
testOrgId = org.id;
});
@@ -219,6 +259,7 @@ describe("Admin Organizations API", () => {
expect(response.status).toBe(200);
expect(response.body.id).toBe(testOrgId);
+ expect(response.body.metadata).toEqual({ tier: "testing", users: 5 });
});
it("should return 404 when getting a non-existent organization", async () => {
@@ -242,7 +283,7 @@ describe("Admin Organizations API", () => {
// Create a test organization to update
const uniqueOrgName = `Test Org ${randomUUID().substring(0, 8)}`;
const org = await prisma.organization.create({
- data: { name: uniqueOrgName },
+ data: { name: uniqueOrgName, metadata: { tier: "testing", users: 5 } },
});
testOrgId = org.id;
});
@@ -260,6 +301,7 @@ describe("Admin Organizations API", () => {
it("should update an organization with valid admin authentication", async () => {
const newName = `Updated Org ${randomUUID().substring(0, 8)}`;
+ const newMetadata = { tier: "updated", users: 10, featureX: true };
const response = await makeZodVerifiedAPICall(
OrganizationResponseSchema,
@@ -267,6 +309,7 @@ describe("Admin Organizations API", () => {
`/api/admin/organizations/${testOrgId}`,
{
name: newName,
+ metadata: newMetadata,
},
`Bearer ${ADMIN_API_KEY}`,
200,
@@ -276,6 +319,7 @@ describe("Admin Organizations API", () => {
expect(response.body).toMatchObject({
id: testOrgId,
name: newName,
+ metadata: newMetadata,
});
// Verify the organization was actually updated in the database
@@ -284,6 +328,7 @@ describe("Admin Organizations API", () => {
});
expect(org).not.toBeNull();
expect(org?.name).toBe(newName);
+ expect(org?.metadata).toEqual(newMetadata);
});
it("should return 404 when updating a non-existent organization", async () => {
@@ -336,7 +381,7 @@ describe("Admin Organizations API", () => {
// Create a test organization to delete
const uniqueOrgName = `Test Org ${randomUUID().substring(0, 8)}`;
const org = await prisma.organization.create({
- data: { name: uniqueOrgName },
+ data: { name: uniqueOrgName, metadata: { tier: "testing", users: 5 } },
});
testOrgId = org.id;
});
@@ -357,7 +402,10 @@ describe("Admin Organizations API", () => {
const uniqueOrgName = `Test Org ${randomUUID().substring(0, 8)}`;
const orgId = (
await prisma.organization.create({
- data: { name: uniqueOrgName },
+ data: {
+ name: uniqueOrgName,
+ metadata: { tier: "testing", users: 5 },
+ },
})
).id;
@@ -440,7 +488,7 @@ describe("Admin Organizations API", () => {
// Create a test organization
const uniqueOrgName = `Test Org ${randomUUID().substring(0, 8)}`;
const org = await prisma.organization.create({
- data: { name: uniqueOrgName },
+ data: { name: uniqueOrgName, metadata: { tier: "testing", users: 5 } },
});
testOrgId = org.id;
@@ -508,7 +556,7 @@ describe("Admin Organizations API", () => {
// Create a test organization
const uniqueOrgName = `Test Org ${randomUUID().substring(0, 8)}`;
const org = await prisma.organization.create({
- data: { name: uniqueOrgName },
+ data: { name: uniqueOrgName, metadata: { tier: "testing", users: 5 } },
});
testOrgId = org.id;
});
@@ -590,7 +638,7 @@ describe("Admin Organizations API", () => {
// Create a test organization
const uniqueOrgName = `Test Org ${randomUUID().substring(0, 8)}`;
const org = await prisma.organization.create({
- data: { name: uniqueOrgName },
+ data: { name: uniqueOrgName, metadata: { tier: "testing", users: 5 } },
});
testOrgId = org.id;
diff --git a/web/src/__tests__/async/projects-api.servertest.ts b/web/src/__tests__/async/projects-api.servertest.ts
index d4f7c27e8e..b0129c4859 100644
--- a/web/src/__tests__/async/projects-api.servertest.ts
+++ b/web/src/__tests__/async/projects-api.servertest.ts
@@ -18,6 +18,7 @@ const ProjectResponseSchema = z.object({
z.object({
id: z.string(),
name: z.string(),
+ metadata: z.object({}).optional(),
retentionDays: z.number().nullable().optional(),
}),
),
@@ -27,6 +28,7 @@ const ProjectResponseSchema = z.object({
const ProjectCreationResponseSchema = z.object({
id: z.string(),
name: z.string(),
+ metadata: z.object({}).optional(),
retentionDays: z.number().nullable().optional(),
});
@@ -34,6 +36,7 @@ const ProjectCreationResponseSchema = z.object({
const ProjectUpdateResponseSchema = z.object({
id: z.string(),
name: z.string(),
+ metadata: z.object({}).optional(),
retentionDays: z.number().nullable().optional(),
});
@@ -113,6 +116,7 @@ describe("Projects API", () => {
expect(response.body.data[0]).toMatchObject({
id: projectId,
name: projectName,
+ metadata: {},
});
});
@@ -174,6 +178,7 @@ describe("Projects API", () => {
it("should create a new project with valid organization API key", async () => {
const uniqueProjectName = `Test Project ${randomUUID().substring(0, 8)}`;
+ const metadata = { plan: "pro", features: ["all"] };
const response = await makeZodVerifiedAPICall(
ProjectCreationResponseSchema,
@@ -181,6 +186,7 @@ describe("Projects API", () => {
"/api/public/projects",
{
name: uniqueProjectName,
+ metadata: metadata,
},
createBasicAuthHeader(orgApiKey, orgSecretKey),
201, // Expected status code is 201 Created
@@ -190,6 +196,7 @@ describe("Projects API", () => {
expect(response.body).toMatchObject({
name: uniqueProjectName,
});
+ expect(response.body.metadata).toEqual(metadata);
expect(response.body.id).toBeDefined();
// Verify the project was actually created in the database
@@ -198,6 +205,7 @@ describe("Projects API", () => {
});
expect(project).not.toBeNull();
expect(project?.name).toBe(uniqueProjectName);
+ expect(project?.metadata).toEqual(metadata);
});
it("should create a new project with retention days", async () => {
@@ -340,6 +348,7 @@ describe("Projects API", () => {
data: {
name: uniqueProjectName,
orgId: "seed-org-id", // Same org ID used for the API key
+ metadata: { plan: "free", features: ["basic"] },
},
});
testProjectId = project.id;
@@ -413,6 +422,33 @@ describe("Projects API", () => {
expect(response.body.retentionDays).toBeUndefined();
});
+ it("should update project metadata", async () => {
+ const newMetadata = { plan: "enterprise", features: ["all", "custom"] };
+ const response = await makeZodVerifiedAPICall(
+ ProjectUpdateResponseSchema,
+ "PUT",
+ `/api/public/projects/${testProjectId}`,
+ {
+ name: "Updated Project Name",
+ metadata: newMetadata,
+ },
+ createBasicAuthHeader(orgApiKey, orgSecretKey),
+ 200, // Expected status code is 200 OK
+ );
+
+ expect(response.status).toBe(200);
+ expect(response.body.name).toBe("Updated Project Name");
+ expect(response.body.metadata).toEqual(newMetadata);
+
+ // Verify the project was updated in the database
+ const project = await prisma.project.findUnique({
+ where: { id: testProjectId },
+ });
+ expect(project).not.toBeNull();
+ expect(project?.name).toBe("Updated Project Name");
+ expect(project?.metadata).toEqual(newMetadata);
+ });
+
it("should return 403 when using project API key instead of organization API key", async () => {
const result = await makeAPICall(
"PUT",
diff --git a/web/src/ee/features/admin-api/organizations/index.ts b/web/src/ee/features/admin-api/organizations/index.ts
index 20adb8e582..df85f05e60 100644
--- a/web/src/ee/features/admin-api/organizations/index.ts
+++ b/web/src/ee/features/admin-api/organizations/index.ts
@@ -13,9 +13,15 @@ export async function handleGetOrganizations(
id: true,
name: true,
createdAt: true,
+ metadata: true,
},
});
- return res.status(200).json({ organizations });
+ return res.status(200).json({
+ organizations: organizations.map((org) => ({
+ ...org,
+ metadata: org.metadata ?? {},
+ })),
+ });
}
export async function handleCreateOrganization(
@@ -35,10 +41,22 @@ export async function handleCreateOrganization(
const { name } = validationResult.data;
+ const { metadata } = req.body;
+ if (metadata !== undefined && typeof metadata !== "object") {
+ try {
+ JSON.parse(metadata);
+ } catch (error) {
+ return res.status(400).json({
+ message: `Invalid metadata. Should be a valid JSON object: ${error}`,
+ });
+ }
+ }
+
// Create the organization in the database
const organization = await prisma.organization.create({
data: {
name,
+ metadata,
},
});
@@ -59,5 +77,6 @@ export async function handleCreateOrganization(
id: organization.id,
name: organization.name,
createdAt: organization.createdAt,
+ metadata: organization.metadata ?? {},
});
}
diff --git a/web/src/ee/features/admin-api/organizations/organizationById.ts b/web/src/ee/features/admin-api/organizations/organizationById.ts
index 0bae7a39cd..5fcca189f1 100644
--- a/web/src/ee/features/admin-api/organizations/organizationById.ts
+++ b/web/src/ee/features/admin-api/organizations/organizationById.ts
@@ -31,6 +31,7 @@ export async function handleGetOrganizationById(
id: true,
name: true,
createdAt: true,
+ metadata: true,
},
});
@@ -38,7 +39,10 @@ export async function handleGetOrganizationById(
return res.status(404).json({ error: "Organization not found" });
}
- return res.status(200).json(organization);
+ return res.status(200).json({
+ ...organization,
+ metadata: organization.metadata ?? {},
+ });
}
export async function handleUpdateOrganization(
@@ -61,6 +65,17 @@ export async function handleUpdateOrganization(
const { name } = validationResult.data;
+ const { metadata } = req.body;
+ if (metadata !== undefined && typeof metadata !== "object") {
+ try {
+ JSON.parse(metadata);
+ } catch (error) {
+ return res.status(400).json({
+ message: `Invalid metadata. Should be a valid JSON object: ${error}`,
+ });
+ }
+ }
+
// Check if organization exists
const existingOrg = await prisma.organization.findUnique({
where: { id: organizationId },
@@ -73,7 +88,7 @@ export async function handleUpdateOrganization(
// Update the organization
const updatedOrganization = await prisma.organization.update({
where: { id: organizationId },
- data: { name },
+ data: { name, metadata },
});
// Log the update
@@ -94,6 +109,7 @@ export async function handleUpdateOrganization(
id: updatedOrganization.id,
name: updatedOrganization.name,
createdAt: updatedOrganization.createdAt,
+ metadata: updatedOrganization.metadata ?? {},
});
}
diff --git a/web/src/ee/features/admin-api/public/projects/createProject.ts b/web/src/ee/features/admin-api/public/projects/createProject.ts
index 1e6413a9d2..473b5b1a66 100644
--- a/web/src/ee/features/admin-api/public/projects/createProject.ts
+++ b/web/src/ee/features/admin-api/public/projects/createProject.ts
@@ -12,7 +12,7 @@ export async function handleCreateProject(
scope: ApiAccessScope,
) {
try {
- const { name, retention } = req.body;
+ const { name, retention, metadata } = req.body;
// Validate project name
try {
@@ -23,6 +23,16 @@ export async function handleCreateProject(
});
}
+ if (metadata !== undefined && typeof metadata !== "object") {
+ try {
+ JSON.parse(metadata);
+ } catch (error) {
+ return res.status(400).json({
+ message: `Invalid metadata. Should be a valid JSON object: ${error}`,
+ });
+ }
+ }
+
// Validate retention days if provided
if (retention !== undefined) {
try {
@@ -69,12 +79,14 @@ export async function handleCreateProject(
name,
orgId: scope.orgId,
retentionDays: retention,
+ metadata,
},
});
return res.status(201).json({
id: project.id,
name: project.name,
+ metadata: project.metadata ?? {},
...(project.retentionDays // Do not add if null or 0
? { retentionDays: project.retentionDays }
: {}),
diff --git a/web/src/ee/features/admin-api/public/projects/projectById/index.ts b/web/src/ee/features/admin-api/public/projects/projectById/index.ts
index 80aebf4989..80cb362223 100644
--- a/web/src/ee/features/admin-api/public/projects/projectById/index.ts
+++ b/web/src/ee/features/admin-api/public/projects/projectById/index.ts
@@ -20,7 +20,7 @@ export async function handleUpdateProject(
scope: ApiAccessScope,
) {
try {
- const { name, retention } = req.body;
+ const { name, retention, metadata } = req.body;
// Validate project name
try {
@@ -31,27 +31,39 @@ export async function handleUpdateProject(
});
}
- // Validate retention days using the schema
- try {
- projectRetentionSchema.parse({ retention });
- } catch (error) {
- return res.status(400).json({
- message: "Invalid retention value. Must be 0 or at least 7 days.",
- });
+ if (metadata !== undefined && typeof metadata !== "object") {
+ try {
+ JSON.parse(metadata);
+ } catch (error) {
+ return res.status(400).json({
+ message: `Invalid metadata. Should be a valid JSON object: ${error}`,
+ });
+ }
}
- // If retention is non-zero, check for data-retention entitlement
- if (retention > 0) {
- const hasDataRetentionEntitlement = hasEntitlementBasedOnPlan({
- entitlement: "data-retention",
- plan: scope.plan,
- });
+ // Validate retention days if provided
+ if (retention !== undefined) {
+ try {
+ projectRetentionSchema.parse({ retention });
+ } catch (error) {
+ return res.status(400).json({
+ message: "Invalid retention value. Must be 0 or at least 7 days.",
+ });
+ }
- if (!hasDataRetentionEntitlement) {
- return res.status(403).json({
- message:
- "The data-retention entitlement is required to set a non-zero retention period.",
+ // If retention is non-zero, check for data-retention entitlement
+ if (retention > 0) {
+ const hasDataRetentionEntitlement = hasEntitlementBasedOnPlan({
+ entitlement: "data-retention",
+ plan: scope.plan,
});
+
+ if (!hasDataRetentionEntitlement) {
+ return res.status(403).json({
+ message:
+ "The data-retention entitlement is required to set a non-zero retention period.",
+ });
+ }
}
}
@@ -63,18 +75,21 @@ export async function handleUpdateProject(
},
data: {
name,
- retentionDays: retention,
+ ...(retention !== undefined ? { retentionDays: retention } : {}),
+ metadata,
},
select: {
id: true,
name: true,
retentionDays: true,
+ metadata: true,
},
});
return res.status(200).json({
id: updatedProject.id,
name: updatedProject.name,
+ metadata: updatedProject.metadata ?? {},
...(updatedProject.retentionDays // Do not add if null or 0
? { retentionDays: updatedProject.retentionDays }
: {}),
diff --git a/web/src/pages/api/public/projects/index.ts b/web/src/pages/api/public/projects/index.ts
index bf5809569c..489690f5a2 100644
--- a/web/src/pages/api/public/projects/index.ts
+++ b/web/src/pages/api/public/projects/index.ts
@@ -3,7 +3,6 @@ import { cors, runMiddleware } from "@/src/features/public-api/server/cors";
import { prisma } from "@langfuse/shared/src/db";
import { logger, redis } from "@langfuse/shared/src/server";
import { handleCreateProject } from "@/src/ee/features/admin-api/public/projects/createProject";
-
import { type NextApiRequest, type NextApiResponse } from "next";
import { hasEntitlementBasedOnPlan } from "@/src/features/entitlements/server/hasEntitlement";
@@ -50,6 +49,7 @@ export default async function handler(
id: true,
name: true,
retentionDays: true,
+ metadata: true,
},
where: {
id: authCheck.scope.projectId,
@@ -61,6 +61,7 @@ export default async function handler(
data: projects.map((project) => ({
id: project.id,
name: project.name,
+ metadata: project.metadata ?? {},
...(project.retentionDays // Do not add if null or 0
? { retentionDays: project.retentionDays }
: {}),
diff --git a/web/src/pages/organization/[organizationId]/settings/index.tsx b/web/src/pages/organization/[organizationId]/settings/index.tsx
index 1817add54c..2d0a30e344 100644
--- a/web/src/pages/organization/[organizationId]/settings/index.tsx
+++ b/web/src/pages/organization/[organizationId]/settings/index.tsx
@@ -42,7 +42,7 @@ export const getOrganizationSettingsPages = ({
showBillingSettings,
isLangfuseCloud,
}: {
- organization: { id: string; name: string };
+ organization: { id: string; name: string; metadata: Record<string, unknown> };
showBillingSettings: boolean;
isLangfuseCloud: boolean;
}): OrganizationSettingsPage[] => [
@@ -57,7 +57,11 @@ export const getOrganizationSettingsPages = ({
<Header title="Debug Information" />
<JSONView
title="Metadata"
- json={{ name: organization.name, id: organization.id }}
+ json={{
+ name: organization.name,
+ id: organization.id,
+ ...organization.metadata,
+ }}
/>
</div>
<SettingsDangerZone
diff --git a/web/src/pages/project/[projectId]/dashboards/[dashboardId]/index.tsx b/web/src/pages/project/[projectId]/dashboards/[dashboardId]/index.tsx
index bd0556da66..920c799e20 100644
--- a/web/src/pages/project/[projectId]/dashboards/[dashboardId]/index.tsx
+++ b/web/src/pages/project/[projectId]/dashboards/[dashboardId]/index.tsx
@@ -212,8 +212,6 @@ export default function DashboardDetail() {
)
: 0;
- debugger;
-
// Create a new widget placement
const newWidgetPlacement: WidgetPlacement = {
id: uuidv4(),
diff --git a/web/src/pages/project/[projectId]/settings/index.tsx b/web/src/pages/project/[projectId]/settings/index.tsx
index 217ca2e2a5..a5bead1d3a 100644
--- a/web/src/pages/project/[projectId]/settings/index.tsx
+++ b/web/src/pages/project/[projectId]/settings/index.tsx
@@ -73,8 +73,8 @@ export const getProjectSettingsPages = ({
showLLMConnectionsSettings,
showProtectedLabelsSettings,
}: {
- project: { id: string; name: string };
- organization: { id: string; name: string };
+ project: { id: string; name: string; metadata: Record<string, unknown> };
+ organization: { id: string; name: string; metadata: Record<string, unknown> };
showBillingSettings: boolean;
showRetentionSettings: boolean;
showLLMConnectionsSettings: boolean;
@@ -94,8 +94,16 @@ export const getProjectSettingsPages = ({
<JSONView
title="Metadata"
json={{
- project: { name: project.name, id: project.id },
- org: { name: organization.name, id: organization.id },
+ project: {
+ name: project.name,
+ id: project.id,
+ ...project.metadata,
+ },
+ org: {
+ name: organization.name,
+ id: organization.id,
+ ...organization.metadata,
+ },
}}
/>
</div>
diff --git a/web/src/server/auth.ts b/web/src/server/auth.ts
index 07fba4dbf6..860581eb0a 100644
--- a/web/src/server/auth.ts
+++ b/web/src/server/auth.ts
@@ -521,6 +521,11 @@ export async function getAuthOptions(): Promise<NextAuthOptions> {
id: orgMembership.organization.id,
name: orgMembership.organization.name,
role: orgMembership.role,
+ metadata:
+ (orgMembership.organization.metadata as Record<
+ string,
+ unknown
+ >) ?? {},
cloudConfig: parsedCloudConfig.data,
projects: orgMembership.organization.projects
.map((project) => {
@@ -535,6 +540,11 @@ export async function getAuthOptions(): Promise<NextAuthOptions> {
role: projectRole,
retentionDays: project.retentionDays,
deletedAt: project.deletedAt,
+ metadata:
+ (project.metadata as Record<
+ string,
+ unknown
+ >) ?? {},
};
})
// Only include projects where the user has the required role
diff --git a/web/types/next-auth.d.ts b/web/types/next-auth.d.ts
index 36d89a77d1..212d2afd4d 100644
--- a/web/types/next-auth.d.ts
+++ b/web/types/next-auth.d.ts
@@ -41,11 +41,13 @@ declare module "next-auth" {
role: Role;
cloudConfig: CloudConfigSchema | undefined;
plan: Plan;
+ metadata: Record<string, unknown>;
projects: {
id: PrismaProject["id"];
name: PrismaProject["name"];
deletedAt: PrismaProject["deletedAt"];
retentionDays: PrismaProject["retentionDays"];
+ metadata: Record<string, unknown>;
role: Role; // include only projects where user has a role
}[];
}[];