> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sagescreen.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate AI analysis for a context

> Loads the context from Redis, sends the job description, role, and role level
to the AI model, and returns enriched context data including:
- **summary** -- AI-generated summary of the role
- **categories** -- Structured evaluation categories
- **category_titles** -- Comma-separated list of category names
- **metrics** -- Assessment metrics for the role

The generated data is also saved to the Prompt Library (PL) service.




## OpenAPI

````yaml /openapi/private/specs/services/context.yml get /context/{context_id}/generate
openapi: 3.1.0
info:
  title: Context Service API
  description: >
    Manages context data for council sages. Context represents the job
    description,

    role, and AI-generated analysis (summary, categories, metrics) used during

    screening interviews.


    ## Authentication

    All endpoints require authentication via one of two methods:

    - **API Key**: Pass the key in the `X-Auth` header (service-to-service
    calls)

    - **JWT Token**: Pass a Bearer token in the `Authorization` header
    (user-facing calls)


    The required permission level is noted per endpoint.


    ## Context Lifecycle

    1. **Create** -- Context is created with job description, role, and role
    level

    2. **Store** -- Context is saved to Redis for fast retrieval during
    screening

    3. **Generate** -- AI analyzes the context to produce summary, categories,
    and metrics

    4. **Save** -- Generated data is persisted to the Prompt Library (PL)
    service


    ## Business Rules

    - Context is stored in Redis for low-latency access during interviews

    - `context_id` must be provided and valid for all read operations

    - The generate endpoint calls AI to produce structured analysis from the job
    context

    - Update and Delete endpoints are not yet implemented (return 501)
  version: 1.0.0
  contact:
    name: Platform Team
servers:
  - url: '{protocol}://{host}:{port}'
    description: Context Service
    variables:
      protocol:
        default: https
        enum:
          - http
          - https
      host:
        default: localhost
      port:
        default: '5000'
security: []
tags:
  - name: Context
    description: Context CRUD and AI generation
  - name: Service
    description: Health checks and initialization
paths:
  /context/{context_id}/generate:
    get:
      tags:
        - Context
      summary: Generate AI analysis for a context
      description: >
        Loads the context from Redis, sends the job description, role, and role
        level

        to the AI model, and returns enriched context data including:

        - **summary** -- AI-generated summary of the role

        - **categories** -- Structured evaluation categories

        - **category_titles** -- Comma-separated list of category names

        - **metrics** -- Assessment metrics for the role


        The generated data is also saved to the Prompt Library (PL) service.
      operationId: generateContext
      parameters:
        - $ref: '#/components/parameters/ContextId'
        - $ref: '#/components/parameters/RequiredPermission_council_sage'
      responses:
        '200':
          description: Context generated and saved successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContextGenerateResponse'
              example:
                id: a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d
                name: Senior Software Engineer
                context: >-
                  We are looking for a senior software engineer with 5+ years of
                  experience in Python and cloud infrastructure...
                role: Software Engineer
                role_level: senior
                council_sage_id: c3d4e5f6-7890-4abc-def0-123456789abc
                summary: >-
                  This role requires a seasoned engineer with deep expertise in
                  Python, AWS, and distributed systems...
                categories:
                  technical_skills:
                    title: Technical Skills
                    description: Python, cloud infrastructure, distributed systems
                  problem_solving:
                    title: Problem Solving
                    description: System design, debugging, optimization
                category_titles: >-
                  "Technical Skills", "Problem Solving", "Communication",
                  "Leadership", "Architecture"
                metrics:
                  complexity: high
                  seniority_match: senior
        '400':
          description: Missing context ID
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: context_id must be set before generating
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          description: Context not found in Redis
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: Context with ID a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d not found
        '500':
          description: AI generation or save error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                systemPromptMissing:
                  summary: System prompt not configured
                  value:
                    error: system_prompt must be set before generating
                aiError:
                  summary: AI generation failed
                  value:
                    error: >-
                      Error generating context data: APIError('Model
                      unavailable')
                saveError:
                  summary: Error saving to PL
                  value:
                    error: >-
                      Error saving context to PL: ConnectionError('Connection
                      refused')
      security:
        - jwtAuth: []
components:
  parameters:
    ContextId:
      name: context_id
      in: path
      required: true
      description: UUID of the context record
      schema:
        type: string
        format: uuid
      example: a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d
    RequiredPermission_council_sage:
      name: X-Permission-Info
      in: header
      required: false
      description: >-
        **Required JWT permission: `council_sage`** (informational only --
        enforced server-side)
      schema:
        type: string
  schemas:
    ContextGenerateResponse:
      type: object
      description: Context enriched with AI-generated analysis
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        context:
          type: string
        role:
          type: string
        role_level:
          type: string
        council_sage_id:
          type: string
          format: uuid
        summary:
          type: string
          description: AI-generated summary of the role requirements
        categories:
          type: object
          additionalProperties: true
          description: Structured evaluation categories produced by AI
        category_titles:
          type: string
          description: Comma-separated quoted category names
        metrics:
          type: object
          additionalProperties: true
          description: Assessment metrics for the role
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: Human-readable error message
  responses:
    Unauthorized:
      description: Authentication failed
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            noApiKey:
              summary: Missing API key
              value:
                error: Unauthorized - API key required
            invalidApiKey:
              summary: Invalid API key
              value:
                error: Unauthorized - Invalid API key
            noToken:
              summary: Missing JWT token
              value:
                error: Unauthorized - No valid token
            invalidToken:
              summary: Invalid or expired JWT
              value:
                error: Unauthorized3
            insufficientPermissions:
              summary: Token lacks required permission
              value:
                error: Unauthorized4
  securitySchemes:
    jwtAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: User JWT token passed in Authorization header

````