- Update default models in config to use `claude-opus-4.6`. - Introduce logging configuration to write logs to a file. - Add correlation ID to error responses for better traceability. - Implement diagnostics for summarizing message requests. - Normalize legacy system messages in the API. - Enhance tests to cover new logging and error handling features. - Update README and documentation to reflect changes in model defaults and logging behavior.
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.requests import Request
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from nexus_claude_api.config import Settings
|
|
from nexus_claude_api.errors import NexusClaudeError, anthropic_error_response
|
|
from nexus_claude_api.nexus_client import NexusClient
|
|
from nexus_claude_api.routes.health import router as health_router
|
|
from nexus_claude_api.routes.messages import router as messages_router
|
|
from nexus_claude_api.routes.models import router as models_router
|
|
|
|
|
|
def create_app(
|
|
settings: Settings | None = None,
|
|
nexus_client: NexusClient | None = None,
|
|
) -> FastAPI:
|
|
resolved_settings = settings or Settings.from_values(require_api_key=False)
|
|
app = FastAPI(title="nexus-claude-api", version="0.1.0")
|
|
app.state.settings = resolved_settings
|
|
app.state.nexus_client = nexus_client or NexusClient(resolved_settings)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(health_router)
|
|
app.include_router(models_router)
|
|
app.include_router(messages_router)
|
|
|
|
@app.exception_handler(NexusClaudeError)
|
|
async def handle_nexus_error(_: Request, exc: NexusClaudeError) -> JSONResponse:
|
|
return anthropic_error_response(
|
|
exc.message,
|
|
status_code=exc.status_code,
|
|
error_type=exc.error_type,
|
|
)
|
|
|
|
return app
|