Severin
February 19, 2025, 9:31am
2
Answer from our docs chatbot :
You’re correct that when a canister makes an HTTPS outcall (including to an LLM service) from a mutate method, the response goes through the consensus layer to ensure all replicas agree on the same result. This is indeed a complex process, and I’ll explain it based on the available information and provide sources for further reading.
The consensus process for HTTPS outcalls works as follows:
Each replica in the subnet makes the HTTP request independently.
The responses are optionally transformed to normalize any differences.
The consensus layer then works to agree on a single response.
You’re right that potentially every response from an LLM could be slightly different. This is why the Internet Computer protocol includes a transformation step to handle such differences.
According to the HTTPS outcalls documentation :
“ICP consensus agrees on a response if at least 2/3 (to be more precise, 2f+1, where f is the number of faulty replicas tolerated by the protocol) of the replicas have the same response for the request as input.”
This means that the replicas don’t necessarily broadcast their responses to every other node. Instead, the consensus mechanism works to find agreement among at least 2/3 of the replicas.
For more detailed information on how this consensus is achieved, you can refer to the following resources:
Achieving Consensus on the Internet Computer
Consensus White Paper
Extended Abstract published at PODC’22
These sources provide in-depth explanations of the consensus mechanism used by the Internet Computer.
For a more specific look at how HTTPS outcalls are processed, including the consensus step, you can review the HTTPS outcalls documentation , which provides a step-by-step breakdown of the process.
Most interesting to you is probably the outcalls documentation. And I suggest you read up on what an ‘idempotency key’ is and/or use something like this