Skip to content

FluxAI Gateway#5

Merged
dewitt4 merged 10 commits intomainfrom
gateway
Oct 27, 2025
Merged

FluxAI Gateway#5
dewitt4 merged 10 commits intomainfrom
gateway

Conversation

@dewitt4
Copy link
Copy Markdown
Contributor

@dewitt4 dewitt4 commented Oct 27, 2025

FluxAI Gateway implementation in Python FastAPI

FluxAI Gateway implementation in Python FastAPI
@dewitt4 dewitt4 self-assigned this Oct 27, 2025
Copilot AI review requested due to automatic review settings October 27, 2025 17:15
@dewitt4 dewitt4 added the enhancement New feature or request label Oct 27, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements the FluxAI Gateway, a FastAPI-based platform for AWS Bedrock cost optimization and observability. The implementation provides intelligent routing, semantic caching, real-time cost tracking, and comprehensive metrics collection for Bedrock API requests.

Key changes:

  • Core FastAPI application with structured logging and Prometheus metrics integration
  • Bedrock client service with model selection and request routing capabilities
  • Semantic caching layer using Redis for cost optimization
  • Cost calculation service with current AWS Bedrock pricing (October 2025)

Reviewed Changes

Copilot reviewed 29 out of 30 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
app/main.py FastAPI application entry point with lifecycle management, metrics endpoint, and CORS configuration
app/services/bedrock_client.py AWS Bedrock client service implementing model invocation and response parsing
app/services/cache.py Redis-based semantic caching service for response caching and cost reduction
app/services/cost_calculator.py Cost calculation service with AWS Bedrock pricing tables
app/services/metrics.py Prometheus metrics service for tracking requests, tokens, costs, and cache performance
app/api/v1/endpoints/bedrock.py Bedrock API endpoints for model invocation with caching and cost tracking
app/db/models.py SQLAlchemy database models for accounts, API keys, and request metrics
app/core/config.py Application configuration using Pydantic settings
docker-compose.yml Development environment with PostgreSQL, Redis, Prometheus, and Grafana
prometheus.yml Prometheus configuration for metrics scraping

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/services/metrics.py Outdated
Comment thread app/api/v1/endpoints/bedrock.py Outdated

if x_enable_cache and cache_service.is_enabled():
cached_response = await cache_service.get(
prompt=request.messages[-1].content,
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accessing request.messages[-1] assumes the messages list is non-empty. If an empty messages list is provided, this will raise an IndexError. Add validation to ensure messages is not empty before accessing the last element.

Copilot uses AI. Check for mistakes.
Comment thread app/api/v1/endpoints/bedrock.py Outdated
# Cache the response
if x_enable_cache and cache_service.is_enabled():
await cache_service.set(
prompt=request.messages[-1].content,
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as comment 3: accessing request.messages[-1] without validating that the list is non-empty will raise an IndexError if messages is empty.

Copilot uses AI. Check for mistakes.
Comment thread app/services/analytics.py Outdated
dewitt4 and others added 2 commits October 27, 2025 10:21
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@dewitt4 dewitt4 requested a review from Copilot October 27, 2025 17:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 29 out of 30 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/services/metrics.py Outdated
Comment on lines +146 to +147
input_cost=cost * (input_tokens / total_tokens) if total_tokens > 0 else 0,
output_cost=cost * (output_tokens / total_tokens) if total_tokens > 0 else 0,
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cost calculation logic is incorrect. It should use the actual input/output pricing ratios from the cost calculator, not proportionally split the total cost by token count. This will result in inaccurate cost attribution between input and output tokens.

Copilot uses AI. Check for mistakes.
Comment thread docker-compose.yml Outdated
dewitt4 and others added 4 commits October 27, 2025 10:26
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@dewitt4 dewitt4 requested a review from Copilot October 27, 2025 18:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 29 out of 30 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

app/services/cost_calculator.py:1

  • Methods calculate_input_cost and calculate_output_cost are called but not defined in the CostCalculator class. The class only has a calculate method that returns a dictionary and a get_pricing method.
"""Cost calculator service."""

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/services/metrics.py Outdated
Comment thread app/services/metrics.py
Comment thread app/services/metrics.py Outdated
dewitt4 and others added 3 commits October 27, 2025 11:08
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@dewitt4 dewitt4 requested a review from Copilot October 27, 2025 18:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 29 out of 30 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

app/services/cost_calculator.py:1

  • The CostCalculator class does not define calculate_input_cost or calculate_output_cost methods. Only the calculate method exists, which returns a dictionary with 'input', 'output', and 'total' keys. Use the calculate method instead and extract the appropriate values.
"""Cost calculator service."""

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dewitt4 dewitt4 merged commit 61cb661 into main Oct 27, 2025
@dewitt4 dewitt4 deleted the gateway branch October 27, 2025 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants