How rohan-girsa/ai-gateway-spring works
AI Gateway is a Spring Boot chat API that accepts requests, prepares provider-neutral LLM calls, and returns JSON replies or SSE streams. Its principal workflow includes session-memory selection, optional document processing, provider-specific request/response mapping, and response delivery; separate endpoints expose history, memory clearing, and configured providers. The README documents these relationships and the major capabilities, but no source excerpts were supplied, so implementation-level call ownership cannot be verified beyond those documented flows.
Main entry points: ChatService.java Chat orchestration · LlmRequest.java LLM request · OpenAiCompatibleProvider.java OpenAI-compatible adapter · AnthropicProvider.java Anthropic adapter
Components 24
API and chat orchestration
- Chat endpoints
src/main/java/com/example/aigateway/web/ChatController.java - Error handling
src/main/java/com/example/aigateway/web/GlobalExceptionHandler.java - Chat orchestration
src/main/java/com/example/aigateway/service/ChatService.java - Prepared chat
src/main/java/com/example/aigateway/service/PreparedChat.java - Chat models
src/main/java/com/example/aigateway/model/ChatRequest.java - Chat response
src/main/java/com/example/aigateway/model/ChatResponse.java
Conversation context
- Session memory
src/main/java/com/example/aigateway/memory/ConversationMemory.java - In-memory store
src/main/java/com/example/aigateway/memory/InMemoryConversationMemory.java - Document handling
src/main/java/com/example/aigateway/document/DocumentService.java - Safe URL fetch
src/main/java/com/example/aigateway/document/DocumentFetcher.java - Text extraction
src/main/java/com/example/aigateway/document/DocumentTextExtractor.java - Provider document support
src/main/java/com/example/aigateway/document/DocumentSupport.java
Provider integration
- Provider registry
src/main/java/com/example/aigateway/provider/ProviderRegistry.java - LLM request
src/main/java/com/example/aigateway/provider/LlmRequest.java - LLM result
src/main/java/com/example/aigateway/provider/LlmResult.java - OpenAI-compatible adapter
src/main/java/com/example/aigateway/provider/openai/OpenAiCompatibleProvider.java - OpenAI mapper
src/main/java/com/example/aigateway/provider/openai/OpenAiMapper.java - Anthropic adapter
src/main/java/com/example/aigateway/provider/anthropic/AnthropicProvider.java - Anthropic mapper
src/main/java/com/example/aigateway/provider/anthropic/AnthropicMapper.java - Perplexity adapter
src/main/java/com/example/aigateway/provider/perplexity/PerplexityAgentProvider.java - Perplexity mapper
src/main/java/com/example/aigateway/provider/perplexity/PerplexityMapper.java
Runtime configuration
- AI settings
src/main/java/com/example/aigateway/config/AiProperties.java
Other components
- API client
- LLM provider APIs
Connections 28
- API client → Chat endpoints: sends requests
README.md - Chat endpoints → Chat orchestration: delegates chat
README.md - Chat orchestration → Prepared chat: prepares request
README.md - Chat orchestration → Session memory: uses session memory
README.md - In-memory store → Session memory: implements
README.md - Chat orchestration → Document handling: handles documents
README.md - Document handling → Safe URL fetch: fetches URLs
README.md - Document handling → Text extraction: extracts text
README.md - Chat orchestration → Provider registry: selects provider
- Chat orchestration → LLM request: creates request
README.md - LLM request → OpenAI mapper: maps request
README.md - LLM request → Anthropic mapper: maps request
README.md - LLM request → Perplexity mapper: maps request
README.md - OpenAI mapper → OpenAI-compatible adapter: builds provider DTO
README.md - Anthropic mapper → Anthropic adapter: builds provider DTO
README.md - Perplexity mapper → Perplexity adapter: builds provider DTO
README.md - OpenAI-compatible adapter → LLM provider APIs: calls API
README.md - Anthropic adapter → LLM provider APIs: calls API
README.md - Perplexity adapter → LLM provider APIs: calls API
README.md - OpenAI-compatible adapter → LLM result: maps response
README.md - Anthropic adapter → LLM result: maps response
README.md - Perplexity adapter → LLM result: maps response
README.md - LLM result → Chat orchestration: returns result
README.md - Chat orchestration → Chat endpoints: returns reply or stream
README.md - Provider document support → OpenAI-compatible adapter: supports file parts
README.md - Provider document support → Anthropic adapter: supports document blocks
README.md - Provider document support → Perplexity adapter: supports input files
README.md - AI settings → Provider registry: configures providers