From 8cf35eb45bf4c32fc8352dff86a9dfadbc4dc2d3 Mon Sep 17 00:00:00 2001 From: nishika26 Date: Thu, 3 Jul 2025 12:45:56 +0530 Subject: [PATCH 1/3] to get project id from api key --- backend/app/api/routes/threads.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/app/api/routes/threads.py b/backend/app/api/routes/threads.py index e0e77fc2..90fe0415 100644 --- a/backend/app/api/routes/threads.py +++ b/backend/app/api/routes/threads.py @@ -9,9 +9,9 @@ from typing import Optional from langfuse.decorators import observe, langfuse_context -from app.api.deps import get_current_user_org, get_db +from app.api.deps import get_current_user_org, get_db, get_current_user_org_project from app.core import logging, settings -from app.models import UserOrganization, OpenAIThreadCreate +from app.models import UserOrganization, OpenAIThreadCreate, UserProjectOrg from app.crud import upsert_thread_result, get_thread_result from app.utils import APIResponse from app.crud.credentials import get_provider_credential @@ -372,7 +372,7 @@ async def start_thread( request: StartThreadRequest, background_tasks: BackgroundTasks, db: Session = Depends(get_db), - _current_user: UserOrganization = Depends(get_current_user_org), + _current_user: UserProjectOrg = Depends(get_current_user_org_project), ): """ Create a new OpenAI thread for the given question and start polling in the background. @@ -383,7 +383,7 @@ async def start_thread( session=db, org_id=_current_user.organization_id, provider="openai", - project_id=request.get("project_id"), + project_id=_current_user.project_id, ) # Configure OpenAI client From 37860eb2ea2157cb27dcb729e3671f0d524acf84 Mon Sep 17 00:00:00 2001 From: nishika26 Date: Thu, 3 Jul 2025 20:34:48 +0530 Subject: [PATCH 2/3] username password auth not allowed --- backend/app/api/deps.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/app/api/deps.py b/backend/app/api/deps.py index 43810c38..7d295758 100644 --- a/backend/app/api/deps.py +++ b/backend/app/api/deps.py @@ -121,6 +121,9 @@ def get_current_user_org_project( organization_id = api_key_record.organization_id project_id = api_key_record.project_id + if not api_key: + raise HTTPException(status_code=401, detail="API Key is required") + return UserProjectOrg( **current_user.model_dump(), organization_id=organization_id, From c3acaeec201140254bb90bef971f0c9c2f865948 Mon Sep 17 00:00:00 2001 From: nishika26 Date: Fri, 4 Jul 2025 17:17:00 +0530 Subject: [PATCH 3/3] dependency --- backend/app/api/deps.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/app/api/deps.py b/backend/app/api/deps.py index 7d295758..fd946e31 100644 --- a/backend/app/api/deps.py +++ b/backend/app/api/deps.py @@ -121,8 +121,8 @@ def get_current_user_org_project( organization_id = api_key_record.organization_id project_id = api_key_record.project_id - if not api_key: - raise HTTPException(status_code=401, detail="API Key is required") + else: + raise HTTPException(status_code=401, detail="Invalid API Key") return UserProjectOrg( **current_user.model_dump(),