Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(api): make a/usage free w no db

amplitudesc5cb97198140
diff --git a/apps/api/src/controllers/v2/agent.ts b/apps/api/src/controllers/v2/agent.ts
index c8c8fdc9b..7d653300e 100644
--- a/apps/api/src/controllers/v2/agent.ts
+++ b/apps/api/src/controllers/v2/agent.ts
@@ -9,10 +9,7 @@ import {
import { logger as _logger } from "../../lib/logger";
import { logRequest } from "../../services/logging/log_job";
import { config } from "../../config";
-import {
- supabase_acuc_only_service,
- supabase_service,
-} from "../../services/supabase";
+import { supabase_service } from "../../services/supabase";
export async function agentController(
req: RequestWithAuth<{}, AgentResponse, AgentRequest>,
@@ -70,22 +67,26 @@ export async function agentController(
});
}
- const client = !!config.SUPABASE_ACUC_URL
- ? supabase_acuc_only_service
- : supabase_service;
+ let freeRequest: any;
- const { data: freeRequest, error: freeRequestError } = await client.rpc(
- "agent_consume_free_request_if_left",
- {
- i_team_id: req.auth.team_id,
- },
- );
+ if (config.USE_DB_AUTHENTICATION) {
+ const { data, error: freeRequestError } = await supabase_service.rpc(
+ "agent_consume_free_request_if_left",
+ {
+ i_team_id: req.auth.team_id,
+ },
+ );
+
+ if (freeRequestError) {
+ throw freeRequestError;
+ }
- if (freeRequestError) {
- throw freeRequestError;
+ freeRequest = data;
}
- const isFreeRequest = !!freeRequest?.[0]?.consumed;
+ const isFreeRequest = config.USE_DB_AUTHENTICATION
+ ? !!freeRequest?.[0]?.consumed
+ : true;
await logRequest({
id: agentId,