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

# Completion

> Initiates a completion request to the configured LLM provider using specified parameters and provided variables. This endpoint abstracts the integration with different model providers, enabling seamless switching between models while maintaining a consistent data model for your application.



## OpenAPI

````yaml post /sdk/v1/prompts/{id}/completion
openapi: 3.0.0
info:
  title: Prompt Foundry API
  version: 1.0.0
  description: The API for managing prompts, tools, evaluations, and evaluation assertions.
servers:
  - url: https://api.promptfoundry.ai
    description: Prompt Foundry Production API
security: []
paths:
  /sdk/v1/prompts/{id}/completion:
    post:
      summary: Completion
      description: >-
        Initiates a completion request to the configured LLM provider using
        specified parameters and provided variables. This endpoint abstracts the
        integration with different model providers, enabling seamless switching
        between models while maintaining a consistent data model for your
        application.
      operationId: completion
      parameters:
        - schema:
            type: string
            example: '1212121'
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GetCompletionBody'
      responses:
        '200':
          description: Successful completion response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateCompletionResponse'
        '400':
          description: Missing or invalid parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import PromptFoundry from '@prompt-foundry/typescript-sdk';

            const client = new PromptFoundry({
              apiKey: process.env['PROMPT_FOUNDRY_API_KEY'], // This is the default and can be omitted
            });

            async function main() {
              const completionCreateResponse = await client.completion.create('1212121');

              console.log(completionCreateResponse.provider);
            }

            main();
        - lang: Python
          source: |-
            import os
            from prompt_foundry_python_sdk import PromptFoundry

            client = PromptFoundry(
                # This is the default and can be omitted
                api_key=os.environ.get("PROMPT_FOUNDRY_API_KEY"),
            )
            completion_create_response = client.completion.create(
                id="1212121",
            )
            print(completion_create_response.provider)
components:
  schemas:
    GetCompletionBody:
      type: object
      properties:
        variables:
          $ref: '#/components/schemas/PromptVariables'
        overrideMessages:
          type: array
          items:
            $ref: '#/components/schemas/ConversationMessage'
          description: Replaces the configured prompt messages when running the prompt.
        appendMessages:
          type: array
          items:
            $ref: '#/components/schemas/ConversationMessage'
          description: >-
            Appended the the end of the configured prompt messages before
            running the prompt.
        user:
          type: string
          description: >-
            A unique identifier representing your end-user, which can help
            monitor and detect abuse.
    CreateCompletionResponse:
      type: object
      properties:
        provider:
          allOf:
            - $ref: '#/components/schemas/LLMProviders'
            - description: The provider of the provided model.
        name:
          type: string
        stats:
          $ref: '#/components/schemas/CompletionStats'
        message:
          allOf:
            - $ref: '#/components/schemas/ConversationMessage'
            - description: The completion message generated by the model.
      required:
        - provider
        - name
        - stats
        - message
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
          description: 'Example: "Prompt ID is required."'
      required:
        - error
    PromptVariables:
      type: object
      additionalProperties:
        type: string
        nullable: true
      description: The template variables added to the prompt when executing the prompt.
    ConversationMessage:
      type: object
      properties:
        content:
          type: array
          items:
            $ref: '#/components/schemas/MessageContentBlockSchema'
        role:
          $ref: '#/components/schemas/PromptMessageRole'
      required:
        - content
        - role
    LLMProviders:
      type: string
      enum:
        - ANTHROPIC
        - OPENAI
      description: The LLM model provider.
    CompletionStats:
      type: object
      properties:
        inputTokenCount:
          type: number
          description: The number of tokens in the input prompt.
        outputTokenCount:
          type: number
          description: The number of tokens in the output completion.
        latency:
          type: number
          description: The time in milliseconds it took to generate the completion.
        cost:
          type: number
          description: The cost of generating the completion.
      required:
        - inputTokenCount
        - outputTokenCount
        - latency
        - cost
    MessageContentBlockSchema:
      oneOf:
        - $ref: '#/components/schemas/TextContentBlock'
        - $ref: '#/components/schemas/ImageBase64ContentBlock'
        - $ref: '#/components/schemas/ToolCallContentBlock'
        - $ref: '#/components/schemas/ToolResultContentBlock'
      discriminator:
        propertyName: type
        mapping:
          TEXT: '#/components/schemas/TextContentBlock'
          IMAGE_BASE64: '#/components/schemas/ImageBase64ContentBlock'
          TOOL_CALL: '#/components/schemas/ToolCallContentBlock'
          TOOL_RESULT: '#/components/schemas/ToolResultContentBlock'
    PromptMessageRole:
      type: string
      enum:
        - assistant
        - system
        - tool
        - user
    TextContentBlock:
      type: object
      properties:
        type:
          type: string
          enum:
            - TEXT
        text:
          type: string
      required:
        - type
        - text
      title: TextContentBlock
    ImageBase64ContentBlock:
      type: object
      properties:
        type:
          type: string
          enum:
            - IMAGE_BASE64
        imageBase64:
          type: string
        mediaType:
          type: string
      required:
        - type
        - imageBase64
        - mediaType
      title: ImageBase64ContentBlock
    ToolCallContentBlock:
      type: object
      properties:
        type:
          type: string
          enum:
            - TOOL_CALL
        toolCall:
          $ref: '#/components/schemas/ToolFunctionCall'
      required:
        - type
        - toolCall
      title: ToolCallContentBlock
    ToolResultContentBlock:
      type: object
      properties:
        type:
          type: string
          enum:
            - TOOL_RESULT
        toolCallId:
          type: string
        result:
          type: string
      required:
        - type
        - toolCallId
        - result
      title: ToolResultContentBlock
    ToolFunctionCall:
      type: object
      properties:
        toolCallId:
          type: string
          description: TOOL_CALL_1
        type:
          type: string
          enum:
            - function
          description: The type of the tool. Currently, only `function` is supported.
        function:
          type: object
          properties:
            arguments:
              type: string
              description: >-
                The arguments to call the function with, as generated by the
                model in JSON format. Note that the model does not always
                generate valid JSON, and may hallucinate parameters not defined
                by your function schema. Validate the arguments in your code
                before calling your function.
            name:
              type: string
              description: The name of the function to call.
          required:
            - arguments
            - name
      required:
        - toolCallId
        - type
        - function

````