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

# Create confidential completions

> This handler processes completions requests in a confidential manner, providing additional
encryption and security measures for sensitive data processing. It supports both streaming and
non-streaming responses while maintaining data confidentiality through AEAD encryption and TEE hardware,
for full private AI compute.

## Returns

Returns a `Result` containing either:
* An HTTP response with the completions result
* A streaming SSE connection for real-time completions
* An `AtomaProxyError` error if the request processing fails

## Errors

Returns `AtomaProxyError::InvalidBody` if:
* The 'stream' field is missing or invalid in the payload

Returns `AtomaProxyError::InternalError` if:
* The inference service request fails
* Response processing encounters errors
* State manager updates fail

## Security Features

* Utilizes AEAD encryption for request/response data
* Supports TEE (Trusted Execution Environment) processing
* Implements secure key exchange using X25519
* Maintains confidentiality throughout the request lifecycle



## OpenAPI

````yaml cloud-api-reference/openapi.yml post /v1/confidential/completions
openapi: 3.1.0
info:
  title: atoma-proxy
  description: ''
  license:
    name: Apache-2.0
    identifier: Apache-2.0
  version: 0.1.0
servers:
  - url: https://api.atoma.network
security: []
tags:
  - name: Completions
    description: OpenAI's API completions v1 endpoint
  - name: Confidential Completions
    description: Atoma's API confidential completions v1 endpoint
  - name: Chat
    description: OpenAI's API chat completions v1 endpoint
  - name: Confidential Chat
    description: Atoma's API confidential chat completions v1 endpoint
  - name: Confidential Embeddings
    description: Atoma's API confidential embeddings v1 endpoint
  - name: Confidential Images
    description: Atoma's API confidential images v1 endpoint
  - name: Embeddings
    description: OpenAI's API embeddings v1 endpoint
  - name: Health
    description: Health check
  - name: Images
    description: OpenAI's API images v1 endpoint
  - name: Models
    description: OpenAI's API models v1 endpoint
  - name: Nodes
    description: Nodes Management
  - name: Node Public Key Selection
    description: Node public key selection
paths:
  /v1/confidential/completions:
    post:
      tags:
        - Confidential Completions
      summary: Create confidential completions
      description: >-
        This handler processes completions requests in a confidential manner,
        providing additional

        encryption and security measures for sensitive data processing. It
        supports both streaming and

        non-streaming responses while maintaining data confidentiality through
        AEAD encryption and TEE hardware,

        for full private AI compute.


        ## Returns


        Returns a `Result` containing either:

        * An HTTP response with the completions result

        * A streaming SSE connection for real-time completions

        * An `AtomaProxyError` error if the request processing fails


        ## Errors


        Returns `AtomaProxyError::InvalidBody` if:

        * The 'stream' field is missing or invalid in the payload


        Returns `AtomaProxyError::InternalError` if:

        * The inference service request fails

        * Response processing encounters errors

        * State manager updates fail


        ## Security Features


        * Utilizes AEAD encryption for request/response data

        * Supports TEE (Trusted Execution Environment) processing

        * Implements secure key exchange using X25519

        * Maintains confidentiality throughout the request lifecycle
      operationId: confidential_completions_create
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ConfidentialComputeRequest'
        required: true
      responses:
        '200':
          description: Confidential chat completions
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ConfidentialComputeResponse'
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: typescript
          label: default
          source: |-
            import { AtomaSDK } from "atoma-sdk";

            const atomaSDK = new AtomaSDK({
              bearerAuth: process.env["ATOMASDK_BEARER_AUTH"] ?? "",
            });

            async function run() {
              const completion = await atomaSDK.confidentialCompletions.create({
                model: "meta-llama/Llama-3.3-70B-Instruct",
                prompt: "Hello, world!",
              });

              console.log(completion.choices[0]);
            }

            run();
        - lang: typescript
          label: streaming
          source: |-
            import { AtomaSDK } from "atoma-sdk";

            const atomaSDK = new AtomaSDK({
              bearerAuth: process.env["ATOMASDK_BEARER_AUTH"] ?? "",
            });

            async function run() {
              const completion = await atomaSDK.confidentialCompletions.createStream({
                model: "meta-llama/Llama-3.3-70B-Instruct",
                prompt: "Hello, world!",
              });

              for await (const chunk of completion) {
                console.log(chunk.choices[0].text);
              }
            }

            run();
        - lang: python
          label: chat_completions_create
          source: |-
            from atoma_sdk import AtomaSDK
            import os

            with AtomaSDK(
                bearer_auth=os.getenv("ATOMASDK_BEARER_AUTH", ""),
            ) as atoma_sdk:

                completion = atoma_sdk.confidential_completions.create(
                  model="meta-llama/Llama-3.3-70B-Instruct",
                  prompt="Hello, how are you?"
                )

                print(completion.choices[0].text)
        - lang: python
          label: streaming
          source: |-
            from atoma_sdk import AtomaSDK
            import os

            with AtomaSDK(
                bearer_auth=os.getenv("ATOMASDK_BEARER_AUTH", ""),
            ) as atoma_sdk:

                completion = atoma_sdk.confidential_completions.create_stream(
                  model="meta-llama/Llama-3.3-70B-Instruct",
                  prompt="Hello, how are you?"
                )

                for chunk in completion:
                  print(chunk.data.choices[0].text)
components:
  schemas:
    ConfidentialComputeRequest:
      type: object
      description: >-
        A request for confidential computation that includes encrypted data and
        associated cryptographic parameters
      required:
        - ciphertext
        - stack_small_id
        - nonce
        - salt
        - client_dh_public_key
        - node_dh_public_key
        - plaintext_body_hash
        - model_name
      properties:
        ciphertext:
          type: string
          description: The encrypted payload that needs to be processed (base64 encoded)
        client_dh_public_key:
          type: string
          description: Client's public key for Diffie-Hellman key exchange (base64 encoded)
        model_name:
          type: string
          description: Model name
        node_dh_public_key:
          type: string
          description: Node's public key for Diffie-Hellman key exchange (base64 encoded)
        nonce:
          type: string
          description: Cryptographic nonce used for encryption (base64 encoded)
        num_compute_units:
          type:
            - integer
            - 'null'
          format: int64
          description: >-
            Number of compute units to be used for the request, for image
            generations,

            as this value is known in advance (the number of pixels to generate)
          minimum: 0
        plaintext_body_hash:
          type: string
          description: >-
            Hash of the original plaintext body for integrity verification
            (base64 encoded)
        salt:
          type: string
          description: Salt value used in key derivation (base64 encoded)
        stack_small_id:
          type: integer
          format: int64
          description: Unique identifier for the small stack being used
          minimum: 0
        stream:
          type:
            - boolean
            - 'null'
          description: Indicates whether this is a streaming request
    ConfidentialComputeResponse:
      type: object
      description: Represents a response from a confidential compute request
      required:
        - ciphertext
        - nonce
      properties:
        ciphertext:
          type: string
          description: Encrypted response body (base64 encoded)
        nonce:
          type: string
          description: Nonce used for encryption (base64 encoded)
        response_hash:
          type:
            - string
            - 'null'
          description: Hash of the response body (base64 encoded)
        signature:
          type:
            - string
            - 'null'
          description: Signature of the response body (base64 encoded)
        usage:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/Usage'
              description: Usage statistics for the request
    Usage:
      type: object
      required:
        - prompt_tokens
        - completion_tokens
        - total_tokens
        - completion_tokens_details
        - prompt_tokens_details
      properties:
        completion_tokens:
          type: integer
          format: int32
          description: The number of completion tokens used
          example: 10
          minimum: 0
        completion_tokens_details:
          $ref: '#/components/schemas/CompletionTokensDetails'
          description: The details of the completion tokens
        prompt_tokens:
          type: integer
          format: int32
          description: The number of prompt tokens used
          example: 10
          minimum: 0
        prompt_tokens_details:
          $ref: '#/components/schemas/PromptTokensDetails'
          description: The details of the prompt tokens
        total_tokens:
          type: integer
          format: int32
          description: The total number of tokens used
          example: 20
          minimum: 0
    CompletionTokensDetails:
      type: object
      description: The details of the completion tokens
      required:
        - accepted_prediction_tokens
        - audio_tokens
        - reasoning_tokens
        - rejected_prediction_tokens
      properties:
        accepted_prediction_tokens:
          type: integer
          format: int32
          description: The number of tokens in the completion
          example: 10
          minimum: 0
        audio_tokens:
          type: integer
          format: int32
          description: The number of audio tokens
          example: 0
          minimum: 0
        reasoning_tokens:
          type: integer
          format: int32
          description: The number of reasoning tokens
          example: 10
          minimum: 0
        rejected_prediction_tokens:
          type: integer
          format: int32
          description: The number of rejected prediction tokens
          example: 0
          minimum: 0
    PromptTokensDetails:
      type: object
      required:
        - audio_tokens
        - cached_tokens
      properties:
        audio_tokens:
          type: integer
          format: int32
          description: The number of audio tokens
          example: 0
          minimum: 0
        cached_tokens:
          type: integer
          format: int32
          description: The number of cached tokens
          example: 10
          minimum: 0
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````