Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

feat(ai): disable credit tracking by default (#1511)

Corentin Thomasset71fdd274a018
diff --git a/.changeset/quiet-models-count.md b/.changeset/quiet-models-count.md
new file mode 100644
index 00000000..ab383eda
--- /dev/null
+++ b/.changeset/quiet-models-count.md
@@ -0,0 +1,5 @@
+---
+'@papra/app': patch
+---
+
+Fully disabled AI credit accounting by default for self-hosted instances to silence "Failed to register AI credit usage" logs.
diff --git a/apps/papra-server/src/modules/ai/ai.config.ts b/apps/papra-server/src/modules/ai/ai.config.ts
index ef8874e4..c8b25e71 100644
--- a/apps/papra-server/src/modules/ai/ai.config.ts
+++ b/apps/papra-server/src/modules/ai/ai.config.ts
@@ -13,6 +13,14 @@ export const aiConfig = {
env: 'AI_IS_ENABLED',
default: false,
},
+ credits: {
+ isEnabled: {
+ doc: 'Whether to enforce AI credit limits and track credit usage. Enable for metered instances; leave disabled for self-hosting.',
+ schema: booleanishSchema,
+ env: 'AI_CREDITS_IS_ENABLED',
+ default: false,
+ },
+ },
adapters: {
anthropic: anthropicAdaptersConfig,
...openAiAdaptersConfig,
diff --git a/apps/papra-server/src/modules/ai/ai.services.ts b/apps/papra-server/src/modules/ai/ai.services.ts
index 6a2efe91..72bbd1cc 100644
--- a/apps/papra-server/src/modules/ai/ai.services.ts
+++ b/apps/papra-server/src/modules/ai/ai.services.ts
@@ -98,16 +98,18 @@ async function generateStructuredData<Schema extends GenericSchema | undefined>(
config,
});
- await checkOrganizationHasSufficientAiCredits({
- organizationId,
- aiCreditsRepository,
- getOrganizationPlan: createGetOrganizationPlanUsecase({
- plansRepository,
- planEntitlementDefinitionRegistry,
- planEntitlementsRepository,
- subscriptionsRepository,
- }),
- });
+ if (config.ai.credits.isEnabled) {
+ await checkOrganizationHasSufficientAiCredits({
+ organizationId,
+ aiCreditsRepository,
+ getOrganizationPlan: createGetOrganizationPlanUsecase({
+ plansRepository,
+ planEntitlementDefinitionRegistry,
+ planEntitlementsRepository,
+ subscriptionsRepository,
+ }),
+ });
+ }
const data = await tanstackChat({
adapter,
@@ -117,13 +119,17 @@ async function generateStructuredData<Schema extends GenericSchema | undefined>(
systemPrompts: systemPrompt ? [systemPrompt] : undefined,
middleware: [
createLogMiddleware({ logger, context: { modelId } }),
- createAiCreditsMiddleware({
- modelId,
- organizationId,
- source,
- logger,
- aiCreditsRepository,
- }),
+ ...(config.ai.credits.isEnabled
+ ? [
+ createAiCreditsMiddleware({
+ modelId,
+ organizationId,
+ source,
+ logger,
+ aiCreditsRepository,
+ }),
+ ]
+ : []),
],
});