HTTP outcalls cycles

When I execute an HTTP outcalls without providing enough cycles, the local replica warns me about the expected amount of cycles required for the call.

For example:

juno-satellite-1 | 2024-02-08 18:15:09.556190970 UTC: [Canister jx5yt-yyaaa-aaaal-abzbq-cai] The http_request resulted into error. RejectionCode: CanisterReject, Error: http_request request sent with 20_000_000 cycles, but 1_603_075_600 cycles are required.

Can I except those required cycles to be similar on mainnet or it’s totally different?

For example here, if I would use 1_603_075_600 (or a bit more), it would work locally but, could I also expect it would work out on mainnet?

I am not really sure weather you actually want to configure cycles cost correctly or you just want to compare local vs mainnet.

But in mainnet cycles cost depends on the response bytes and few more variables.
Which you can configure using max_response_bytes variable.
https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-http_request:~:text=the%20requested%20URL-,max_response_bytes,-%2D%20optional%2C%20specifies%20the

The cost for an HTTPS outcall is calculated using the formula (3_000_000 + 60_000 * n) * n for the base fee and 400 * n each request byte and 800 * n for each response byte, where n is the number of nodes in the subnet. (From the docs)

1 Like

Thanks for the answer, I’ll have a look in detail tomorrow.

What I wanted to know is whether I can trust the local error message. When the local replica tells me a request would need 1_603_075_600 cycles, can I expect for the same payload and exact same query and response that the same amount of cycles would be required on mainnet as well?

I’ve got some “local environment trust” issues probably :wink:.

1 Like

The cost depends on the subnet size you’re running on. So I would expect that mainnet would cost ~13x more than local if you’re running on a normal application subnet.
Maybe it would help your trust issues if you simply tried to make a call on mainnet and see how much the error message demands there?

1 Like

Thanks Severin for the simple explanation.

I guess it’s what it is meant in the documentation with “Just like with other functions, the cost is scaled to account for larger subnets.”.

Yes, that’s what this means. You can also have a look on the gas cost page for the exact calculation

1 Like