Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x | import {
Controller,
Get,
Param,
Query,
NotFoundException,
} from '@nestjs/common';
import {
ApiTags,
ApiOperation,
ApiResponse,
ApiParam,
ApiQuery,
} from '@nestjs/swagger';
import { LlmCallLogsService } from './llm-call-logs.service';
import { LlmCallLog } from '../core-entities/llm-call-log.entity';
/**
* LLM call logs track all requests made to LLM providers.
*
* Each log records:
* - Request details (model, prompt tokens, parameters)
* - Response details (completion, output tokens, latency)
* - Status (pending, success, error)
* - Cost information
*
* Use these endpoints to monitor LLM usage, debug failed requests,
* and analyze token consumption across sessions.
*/
@ApiTags('llm-call-logs')
@Controller('llm-call-logs')
export class LlmCallLogsController {
constructor(private readonly llmCallLogsService: LlmCallLogsService) {}
@Get()
@ApiOperation({
summary: 'List LLM call logs with filters',
description:
'Query LLM call logs with optional filters for session, input, provider, or status. Supports pagination.',
})
@ApiQuery({
name: 'sessionId',
required: false,
description: 'Filter by session UUID',
})
@ApiQuery({
name: 'sessionInputId',
required: false,
description: 'Filter by session input UUID',
})
@ApiQuery({
name: 'provider',
required: false,
description: 'Filter by provider name (e.g., gemini, openrouter)',
})
@ApiQuery({
name: 'status',
required: false,
description: 'Filter by status (pending, success, error)',
})
@ApiQuery({
name: 'limit',
required: false,
description: 'Maximum number of results',
example: 50,
})
@ApiQuery({
name: 'offset',
required: false,
description: 'Offset for pagination',
example: 0,
})
@ApiResponse({
status: 200,
description: 'List of LLM call logs with total count',
schema: {
properties: {
logs: {
type: 'array',
items: { $ref: '#/components/schemas/LlmCallLog' },
},
total: { type: 'number' },
},
},
})
async findAll(
@Query('sessionId') sessionId?: string,
@Query('sessionInputId') sessionInputId?: string,
@Query('provider') provider?: string,
@Query('status') status?: string,
@Query('limit') limit?: string,
@Query('offset') offset?: string,
): Promise<{ logs: LlmCallLog[]; total: number }> {
return this.llmCallLogsService.findAll({
sessionId,
sessionInputId,
provider,
status,
limit: limit ? parseInt(limit, 10) : undefined,
offset: offset ? parseInt(offset, 10) : undefined,
});
}
@Get('session-input/:inputId')
@ApiOperation({
summary: 'Get logs for a specific session input',
description:
'Returns all LLM call logs associated with a specific session input.',
})
@ApiParam({
name: 'inputId',
description: 'Session input UUID',
format: 'uuid',
})
@ApiQuery({ name: 'limit', required: false, description: 'Maximum results' })
@ApiQuery({
name: 'offset',
required: false,
description: 'Pagination offset',
})
@ApiResponse({
status: 200,
description: 'List of logs for the input',
schema: {
properties: { logs: { type: 'array' }, total: { type: 'number' } },
},
})
async findBySessionInputId(
@Param('inputId') inputId: string,
@Query('limit') limit?: string,
@Query('offset') offset?: string,
): Promise<{ logs: LlmCallLog[]; total: number }> {
return this.llmCallLogsService.findBySessionInputId(
inputId,
limit ? parseInt(limit, 10) : undefined,
offset ? parseInt(offset, 10) : undefined,
);
}
@Get('session/:sessionId')
@ApiOperation({
summary: 'Get logs for a session',
description: 'Returns all LLM call logs associated with a session.',
})
@ApiParam({ name: 'sessionId', description: 'Session UUID', format: 'uuid' })
@ApiQuery({ name: 'limit', required: false, description: 'Maximum results' })
@ApiQuery({
name: 'offset',
required: false,
description: 'Pagination offset',
})
@ApiResponse({
status: 200,
description: 'List of logs for the session',
schema: {
properties: { logs: { type: 'array' }, total: { type: 'number' } },
},
})
async findBySessionId(
@Param('sessionId') sessionId: string,
@Query('limit') limit?: string,
@Query('offset') offset?: string,
): Promise<{ logs: LlmCallLog[]; total: number }> {
return this.llmCallLogsService.findBySessionId(
sessionId,
limit ? parseInt(limit, 10) : undefined,
offset ? parseInt(offset, 10) : undefined,
);
}
@Get(':id')
@ApiOperation({ summary: 'Get a single LLM call log by ID' })
@ApiParam({ name: 'id', description: 'Log UUID', format: 'uuid' })
@ApiResponse({ status: 200, description: 'Log found', type: LlmCallLog })
@ApiResponse({ status: 404, description: 'Log not found' })
async findById(@Param('id') id: string): Promise<LlmCallLog> {
try {
return await this.llmCallLogsService.findById(id);
} catch (error) {
throw new NotFoundException(error.message || 'LLM call log not found');
}
}
}
|