Spaces:
Running
Running
Fix: sessions tracking now works correctly in dashboard and JSON
Browse files- Added `track_request` calls in services.py for both single-model and fallback paths
- Sessions now show in `/admin` and `/api/admin/sessions`
- Added `/` root endpoint to show active sessions count
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- .claude/settings.local.jsonAdded+25
- .envAdded+28
- __pycache__/server.cpython-312.pycAdded
- __pycache__/server.cpython-314.pycAdded
- api/__pycache__/__init__.cpython-312.pycAdded
- api/__pycache__/__init__.cpython-314.pyc
- api/__pycache__/admin.cpython-314.pycAdded
- api/__pycache__/app.cpython-312.pycAdded
- api/__pycache__/app.cpython-314.pyc
- api/__pycache__/command_utils.cpython-314.pyc
- api/__pycache__/dependencies.cpython-314.pyc
- api/__pycache__/detection.cpython-314.pyc
- api/__pycache__/gateway_model_ids.cpython-314.pyc
- api/__pycache__/model_router.cpython-314.pyc
- api/__pycache__/optimization_handlers.cpython-314.pyc
- api/__pycache__/routes.cpython-314.pyc
- api/__pycache__/runtime.cpython-314.pyc
- api/__pycache__/services.cpython-314.pyc
- api/__pycache__/validation_log.cpython-314.pyc
- api/models/__pycache__/__init__.cpython-314.pyc
- api/models/__pycache__/anthropic.cpython-314.pyc
- api/models/__pycache__/responses.cpython-314.pyc
- api/routes.py+15-8
- api/services.py+3
- api/web_tools/__pycache__/__init__.cpython-314.pyc
- api/web_tools/__pycache__/constants.cpython-314.pyc
- api/web_tools/__pycache__/egress.cpython-314.pyc
- api/web_tools/__pycache__/parsers.cpython-314.pyc
- api/web_tools/__pycache__/request.cpython-314.pyc
- api/web_tools/__pycache__/streaming.cpython-314.pyc
- config/__pycache__/__init__.cpython-314.pyc
- config/__pycache__/constants.cpython-314.pyc
- config/__pycache__/logging_config.cpython-314.pyc
- config/__pycache__/nim.cpython-314.pyc
- config/__pycache__/provider_catalog.cpython-314.pyc
- config/__pycache__/provider_ids.cpython-314.pyc
- config/__pycache__/settings.cpython-314.pyc
- core/__pycache__/__init__.cpython-314.pyc
- core/__pycache__/model_capabilities.cpython-314.pycAdded
- core/__pycache__/rate_limit.cpython-314.pyc
- core/__pycache__/session_tracker.cpython-314.pycAdded
- core/__pycache__/task_detector.cpython-314.pycAdded
- core/anthropic/__pycache__/__init__.cpython-314.pyc
- core/anthropic/__pycache__/content.cpython-314.pyc
- core/anthropic/__pycache__/conversion.cpython-314.pyc
- core/anthropic/__pycache__/errors.cpython-314.pyc
- core/anthropic/__pycache__/native_messages_request.cpython-314.pyc
- core/anthropic/__pycache__/provider_stream_error.cpython-314.pyc
- core/anthropic/__pycache__/server_tool_sse.cpython-314.pyc
- core/anthropic/__pycache__/sse.cpython-314.pyc
12345678910111213141516171819202122232425{ "permissions": { "allow": [ "Bash(uv run *)", "Bash(python -c \"from api.app import create_app; app = create_app\\(\\); print\\([r.path for r in app.routes if 'admin' in r.path]\\)\")", "Bash(python -m uvicorn server:app --host 0.0.0.0 --port 8082)", "Bash(.\\\\.venv\\\\Scripts\\\\python -m uvicorn server:app --host 0.0.0.0 --port 8082)", "Bash(git add *)", "Bash(git commit -m ' *)", "Bash(git push *)" ] }, "enableAllProjectMcpServers": true, "enabledMcpjsonServers": [ "StitchMCP", "figma-dev-mode-mcp-server", "github", "tavily", "context7", "archmind", "office", "llm_wiki", "vercel" ]}12345678910111213141516171819202122232425262728NVIDIA_NIM_API_KEY_QWEN="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"NVIDIA_NIM_API_KEY_GLM="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"NVIDIA_NIM_API_KEY_SEED_OSS="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"NVIDIA_NIM_API_KEY_STEPFUN="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"NVIDIA_NIM_API_KEY_MISTRAL_LARGE="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"NVIDIA_NIM_API_KEY_DRACARYS="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"NVIDIA_NIM_API_KEY_NEMOTRON="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"MODEL="nvidia_nim/stepfun-ai/step-3.5-flash,nvidia_nim/qwen/qwen3-coder-480b-a35b-instruct,nvidia_nim/mistralai/mistral-large-3-675b-instruct-2512,nvidia_nim/abacusai/dracarys-llama-3.1-70b-instruct,nvidia_nim/z-ai/glm4.7,nvidia_nim/bytedance/seed-oss-36b-instruct,nvidia_nim/mistralai/mistral-nemotron"ADVERTISE_ONLY_CONFIGURED_MODELS="true"
# Additional NVIDIA NIM fallback modelsNVIDIA_NIM_FALLBACK_MODELS="nvidia_nim/qwen/qwen3-coder-480b-a35b-instruct,nvidia_nim/z-ai/glm4.7,nvidia_nim/bytedance/seed-oss-36b-instruct"
# Auto-routing priority: Fast/Efficient models first, then heavy reasoning models.#AUTO_MODEL_PRIORITY="nvidia_nim/stepfun-ai/step-3.5-flash,nvidia_nim/bytedance/seed-oss-36b-instruct,nvidia_nim/z-ai/glm4.7,nvidia_nim/mistralai/mistral-nemotron,nvidia_nim/abacusai/dracarys-llama-3.1-70b-instruct,nvidia_nim/qwen/qwen3-coder-480b-a35b-instruct,nvidia_nim/mistralai/mistral-large-3-675b-instruct-2512"
#GROQ_CLOUD_API_KEY="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"#CEREBRAS_API_KEY="csk-2ewy2h26eeph4yex94kmjnfwwx35pdpyyxkv3j6wcj4cxc3t"
LOG_RAW_API_PAYLOADS="true"# Disable API key authentication (allow requests without auth)ANTHROPIC_AUTH_TOKEN=""
#DatabaseDATABASE_URL="postgresql+asyncpg://postgres:%40%23yash123%4023@db.tywafxkhdymjomvikkxw.supabase.co:6543/postgres"
LOG_API_ERROR_TRACEBACKS=" true\4 unmodified lines56789102 unmodified lines1314151617181992 unmodified lines11211311411511611711811912012 unmodified lines13313413513613713813913 unmodified lines15315415515615715815934 unmodified lines1941951961971981992002012022034 unmodified linesfrom config.settings import Settingsfrom core.anthropic import get_token_countfrom providers.registry import ProviderRegistryfrom . import dependencies2 unmodified linesfrom .models.anthropic import MessagesRequest, TokenCountRequestfrom .models.responses import ModelResponse, ModelsListResponsefrom .services import ClaudeProxyServicefrom providers.nvidia_nim import metrics as nvidia_nim_metricsrouter = APIRouter()92 unmodified linessupports_thinking = Noneif provider_registry is not None:# model_id for registry lookups should be provider-prefixedprovider, model_id = ref.split("/", 1) if "/" in ref else ("nvidia_nim", ref)supports_thinking = provider_registry.cached_model_supports_thinking(provider, model_id)_append_provider_model_variants(models, seen, ref, supports_thinking=supports_thinking)# Add a virtual `auto` model that maps to the configured MODEL and enables# automatic fallback behavior when used by clients.12 unmodified linesfiltered = [mfor m in modelsif "claude" not in (m.id or "").lower() and "claude" not in (m.display_name or "").lower()]# Ensure `auto` model remains available even if filtering removed others.if not any(m.id == gateway_model_id("auto") for m in filtered):13 unmodified lines)# =============================================================================# Routes# =============================================================================34 unmodified linessettings: Settings = Depends(get_settings), _auth=Depends(require_api_key)):"""Root endpoint."""return {"status": "ok","provider": settings.provider_type,"model": settings.model,}4 unmodified lines567891011122 unmodified lines15161718192092 unmodified lines11311411511611711811912012112212312412512612712 unmodified lines14014114214314414514614713 unmodified lines16116216316416516634 unmodified lines2012022032042052062072082092104 unmodified linesfrom config.settings import Settingsfrom core.anthropic import get_token_countfrom core.session_tracker import SessionTrackerfrom providers.nvidia_nim import metrics as nvidia_nim_metricsfrom providers.registry import ProviderRegistryfrom . import dependencies2 unmodified linesfrom .models.anthropic import MessagesRequest, TokenCountRequestfrom .models.responses import ModelResponse, ModelsListResponsefrom .services import ClaudeProxyServicerouter = APIRouter()92 unmodified linessupports_thinking = Noneif provider_registry is not None:# model_id for registry lookups should be provider-prefixedprovider, model_id = (ref.split("/", 1) if "/" in ref else ("nvidia_nim", ref))supports_thinking = provider_registry.cached_model_supports_thinking(provider, model_id)_append_provider_model_variants(models, seen, ref, supports_thinking=supports_thinking)# Add a virtual `auto` model that maps to the configured MODEL and enables# automatic fallback behavior when used by clients.12 unmodified linesfiltered = [mfor m in modelsif "claude" not in (m.id or "").lower()and "claude" not in (m.display_name or "").lower()]# Ensure `auto` model remains available even if filtering removed others.if not any(m.id == gateway_model_id("auto") for m in filtered):13 unmodified lines)# =============================================================================# Routes# =============================================================================34 unmodified linessettings: Settings = Depends(get_settings), _auth=Depends(require_api_key)):"""Root endpoint."""tracker = SessionTracker.get_instance()return {"status": "ok","active_sessions": len(tracker._sessions),}
186 unmodified lines187188189190191192186 unmodified linesthinking_enabled=resolved.thinking_enabled,)request_id = f"req_{uuid.uuid4().hex[:12]}"logger.info("API_REQUEST: request_id={} model={} messages={}",186 unmodified lines187188189190191192193194195186 unmodified linesthinking_enabled=resolved.thinking_enabled,)session_id = self._get_session_id(request_data)await self._session_tracker.track_request(session_id, resolved.provider_id)request_id = f"req_{uuid.uuid4().hex[:12]}"logger.info("API_REQUEST: request_id={} model={} messages={}",
.claude/settings.local.jsonAdded+25
.envAdded+28
__pycache__/server.cpython-312.pycAdded
__pycache__/server.cpython-314.pycAdded
api/__pycache__/__init__.cpython-312.pycAdded
api/__pycache__/__init__.cpython-314.pyc
api/__pycache__/admin.cpython-314.pycAdded
api/__pycache__/app.cpython-312.pycAdded
api/__pycache__/app.cpython-314.pyc
api/__pycache__/command_utils.cpython-314.pyc
api/__pycache__/dependencies.cpython-314.pyc
api/__pycache__/detection.cpython-314.pyc
api/__pycache__/gateway_model_ids.cpython-314.pyc
api/__pycache__/model_router.cpython-314.pyc
api/__pycache__/optimization_handlers.cpython-314.pyc
api/__pycache__/routes.cpython-314.pyc
api/__pycache__/runtime.cpython-314.pyc
api/__pycache__/services.cpython-314.pyc
api/__pycache__/validation_log.cpython-314.pyc
api/models/__pycache__/__init__.cpython-314.pyc
api/models/__pycache__/anthropic.cpython-314.pyc
api/models/__pycache__/responses.cpython-314.pyc
api/routes.py+15-8
api/services.py+3
api/web_tools/__pycache__/__init__.cpython-314.pyc
api/web_tools/__pycache__/constants.cpython-314.pyc
api/web_tools/__pycache__/egress.cpython-314.pyc
api/web_tools/__pycache__/parsers.cpython-314.pyc
api/web_tools/__pycache__/request.cpython-314.pyc
api/web_tools/__pycache__/streaming.cpython-314.pyc
config/__pycache__/__init__.cpython-314.pyc
config/__pycache__/constants.cpython-314.pyc
config/__pycache__/logging_config.cpython-314.pyc
config/__pycache__/nim.cpython-314.pyc
config/__pycache__/provider_catalog.cpython-314.pyc
config/__pycache__/provider_ids.cpython-314.pyc
config/__pycache__/settings.cpython-314.pyc
core/__pycache__/__init__.cpython-314.pyc
core/__pycache__/model_capabilities.cpython-314.pycAdded
core/__pycache__/rate_limit.cpython-314.pyc
core/__pycache__/session_tracker.cpython-314.pycAdded
core/__pycache__/task_detector.cpython-314.pycAdded
core/anthropic/__pycache__/__init__.cpython-314.pyc
core/anthropic/__pycache__/content.cpython-314.pyc
core/anthropic/__pycache__/conversion.cpython-314.pyc
core/anthropic/__pycache__/errors.cpython-314.pyc
core/anthropic/__pycache__/native_messages_request.cpython-314.pyc
core/anthropic/__pycache__/provider_stream_error.cpython-314.pyc
core/anthropic/__pycache__/server_tool_sse.cpython-314.pyc
core/anthropic/__pycache__/sse.cpython-314.pyc