feat: API endpoint for LLM call logs by job_id

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
master
oabrivard 3 months ago
parent 9fffde8312
commit dafec2591b

@ -0,0 +1,37 @@
//! Handler for LLM call log viewing.
use axum::extract::{Path, State};
use axum::response::IntoResponse;
use axum::Json;
use uuid::Uuid;
use crate::app_state::AppState;
use crate::db;
use crate::errors::AppError;
use crate::middleware::auth::AuthUser;
/// GET /api/v1/llm-logs/:job_id
///
/// Returns all LLM call log entries for a generation job.
pub async fn get_logs(
auth_user: AuthUser,
State(state): State<AppState>,
Path(job_id): Path<Uuid>,
) -> Result<impl IntoResponse, AppError> {
// Verify the job_id belongs to a synthesis owned by this user
let synthesis = sqlx::query_scalar::<_, Uuid>(
"SELECT id FROM syntheses WHERE job_id = $1 AND user_id = $2 LIMIT 1",
)
.bind(job_id)
.bind(auth_user.id)
.fetch_optional(&state.pool)
.await?;
if synthesis.is_none() {
return Err(AppError::NotFound("No synthesis found for this job".into()));
}
let logs = db::llm_call_log::list_by_job_id(&state.pool, auth_user.id, job_id).await?;
Ok(Json(logs))
}

@ -5,6 +5,7 @@ pub mod auth;
pub mod config; pub mod config;
pub mod generation; pub mod generation;
pub mod health; pub mod health;
pub mod llm_logs;
pub mod settings; pub mod settings;
pub mod sources; pub mod sources;
pub mod syntheses; pub mod syntheses;

@ -57,6 +57,8 @@ pub fn build_router(state: AppState, config: &AppConfig) -> Router {
// Article history & provenance routes (authenticated) // Article history & provenance routes (authenticated)
.route("/article-history", get(handlers::article_history::list_history)) .route("/article-history", get(handlers::article_history::list_history))
.route("/syntheses/{id}/provenance", get(handlers::article_history::get_provenance)) .route("/syntheses/{id}/provenance", get(handlers::article_history::get_provenance))
// LLM call log routes (authenticated)
.route("/llm-logs/{job_id}", get(handlers::llm_logs::get_logs))
// Syntheses CRUD routes (authenticated) // Syntheses CRUD routes (authenticated)
.route("/syntheses", get(handlers::syntheses::list)) .route("/syntheses", get(handlers::syntheses::list))
.route("/syntheses/{id}", get(handlers::syntheses::get)) .route("/syntheses/{id}", get(handlers::syntheses::get))

Loading…
Cancel
Save