---
title: "Handles confidential image generation requests"
method: POST
path: "/v1/confidential/images/generations"
tags: ["confidential-images"]
---

# Handles confidential image generation requests

`POST /v1/confidential/images/generations`

This handler processes image generation requests with confidential computing requirements,
tracking metrics and managing the encryption of responses. It follows the same core flow
as the standard image generations handler but ensures the response is encrypted according
to the client's confidential computing requirements.

# Arguments

* `request_metadata` - Extension containing request context including encryption metadata
* `state` - Application state containing service URLs and shared resources
* `payload` - The image generation request body as JSON

# Returns

Returns a `Result` containing either:
* `Ok(Json<Value>)` - The encrypted response from the image service
* `Err(AtomaServiceError)` - An error if the request processing fails

# Metrics

* Increments `IMAGE_GEN_NUM_REQUESTS` counter with model label
* Records request duration in `IMAGE_GEN_LATENCY_METRICS` histogram

# Errors

Returns `AtomaServiceError::InternalError` if:
* Image generation request fails
* Response encryption fails
* Stack compute units update fails

## Request body

- ConfidentialComputeRequest — A request for confidential computation that includes encrypted data and associated cryptographic parameters
  - `ciphertext` string, required — The encrypted payload that needs to be processed (base64 encoded)
  - `client_dh_public_key` string, required — Client's public key for Diffie-Hellman key exchange (base64 encoded)
  - `model_name` string, required — Model name
  - `node_dh_public_key` string, required — Node's public key for Diffie-Hellman key exchange (base64 encoded)
  - `nonce` string, required — Cryptographic nonce used for encryption (base64 encoded)
  - `num_compute_units` integer, nullable — 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)
  - `plaintext_body_hash` string, required — Hash of the original plaintext body for integrity verification (base64 encoded)
  - `salt` string, required — Salt value used in key derivation (base64 encoded)
  - `stack_small_id` integer, required — Unique identifier for the small stack being used
  - `stream` boolean, nullable — Indicates whether this is a streaming request

## Response `200`

Confidential images generated successfully

- ConfidentialComputeResponse — Represents a response from a confidential compute request
  - `ciphertext` string, required — Encrypted response body (base64 encoded)
  - `nonce` string, required — Nonce used for encryption (base64 encoded)
  - `response_hash` string, nullable — Hash of the response body (base64 encoded)
  - `signature` string, nullable — Signature of the response body (base64 encoded)
  - `usage` CompletionUsage — Represents the completion usage. This is used to represent the completion usage in the chat completion request. It can be either a completion usage or a completion chunk usage.
    - `completion_tokens` integer, required — Number of tokens in the completion.
    - `prompt_tokens` integer, required — Number of tokens in the prompt.
    - `prompt_tokens_details` PromptTokensDetails — Represents the prompt tokens details. This is used to represent the prompt tokens details in the chat completion request. It can be either a prompt tokens details or a prompt tokens details choice.
      - `cached_tokens` integer, required — Number of tokens in the prompt that were cached.
    - `total_tokens` integer, required — Total number of tokens used (prompt + completion).

## Other responses

- `500` — Internal server error

---

[API](https://skmtc.net/atomaai/apis/atoma-service.md) · [All operations](https://skmtc.net/atomaai/apis/atoma-service/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/atomaai/atoma-service/revisions/a3d329cb3125/schema)
