public/Invoke-ClaudeAPIRequest.ps1

function Invoke-ClaudeAPIRequest {

    [CmdletBinding()]
    param(

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$FilePath,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$InstructionFilePath,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Token

    )
    process{

        $ErrorActionPreference = 'Stop'

        try {

            # Read the file content
            $FileContent = Get-Content -Path $FilePath -Raw -ErrorAction Stop

            # Path to your instructions file
            $instructionsContent = Get-Content -Path $InstructionFilePath -Raw -ErrorAction Stop

            # Create the request body
            $requestBody = @{
                model = "claude-3-7-sonnet-20250219"  # Use the current available model
                max_tokens = 4096  # Remove quotes, use numeric value
                #conversation_id = "null"
                messages = @(
                    @{
                        role = "user"
                        content = @(
                            @{
                                type = "text"
                                text = "$instructionsContent
 
            HERE IS THE FILE CONTENT:
 
            $fileContent"

                            }
                        )
                    }
                )
            } | ConvertTo-Json -Depth 10

            # Set the headers
            $headers = @{
                "x-api-key" = $Token
                "anthropic-version" = "2023-06-01"
                "content-type" = "application/json"
            }

            # Make the API request
            $response = Invoke-RestMethod -Uri "https://api.anthropic.com/v1/messages" -Method Post -Headers $headers -Body $requestBody -ContentType "application/json"

            # Display the response
            $response

        }
        catch {

            $_.Exception.Message

        } # try catch

    } # process

} # function