Http request cycle costs

Is there any current cost breakdown on the new HTTP request feature?
I’m currently looking to pull xml data from sites and it’s costing more than i hoped.
My scenario is a GET request with no headers and getting a ~19kb file. Currently this is costing ~0.21T cycles per request which is very cost prohibitive for my scenario.
My alternative is to have something offchain updating onchain data like an oracle.
Any insight or advice would be great

2 Likes

HTTP outcalls feature is charged for when being used. The current pricing is defined to charge a base fee of 400m cycles for an HTTP request in addition to 100K cycles per request byte and per max_response_bytes byte. Because of the per-request fixed cost and the overhead of HTTP requests, e.g., due to headers, it is advantageous from a cost perspective to make fewer requests with larger responses to retrieve the same information as with a larger number of smaller requests, if this is feasible from an application perspective. The cycles provided with the call must be sufficient for covering the cost of the request, excessive cycles are returned to the caller.

The current pricing is defined to be rather conservative (expensive) and prices may change in the future with the introduction of an update of the pricing model. However, note that an HTTP outcall with a small response, like the ones used for querying financial APIs, only costs fractions of a USD cent, which is substantially cheaper than fees charged for a call by oracles on most blockchains.

The cost breakdown is explained here: Internet Computer Content Validation Bootstrap

7 Likes

Unfortunately my requests are very text heavy and i can’t seem to rely on compression from the other end. So I’ll have to consider my options. I appreciate the help!

1 Like

Do you have an example of the “financial feed” Api you used to call to demonstrate?

Here’s a Motoko example: examples/motoko/defi at master · dfinity/examples · GitHub

And here’s a Rust example: examples/rust/defi at master · dfinity/examples · GitHub

Just chiming in: with the cost function that @Ang gave, shouldn’t the price of a call for fetching 19kB be something like:
400 * 10^6 + 19000 * 10^5 so somewhere around 2.3 * 10^9 so two orders of magnitude lower? (0.21T seems more aligned with fetching 2MB of data)

1 Like

I think comparing HTTP outcalls pricing to pricing of third party oracle services is regressive.

HTTP outcalls represent SO MUCH MORE. They are essentially a way for a “world computer” to interface with the external world with the language spoken by the entire internet, which is HTTP.

We are not looking to just build exchanges on the IC. We are looking to build any and every app that exists on the internet.

If we are going up against all forms of traditional hosting, we need to do better. Of course, we should be accounting for the replicated compute that occurs on 13 different nodes.

Just my 2 cents :slight_smile:

1 Like

I think that might be due to the way the call works. The caller needs to explicitly set the max_response_bytes or pay the entire 2MB payload costs as described here, point 5:
https://internetcomputer.org/docs/current/developer-docs/integrations/http_requests/http_requests-how-it-works#how-an-https-outcall-is-processed-by-the-ic

2 Likes

Nice find, I’ll have to try out setting the max

Does the cost go down with less data you send over the network? Wondering how cost changes as you send less data over the network. Is there a set floor price per request?

You can see the cost table here. There is a fixed price per HTTP request, and then an additional charge per request/response byte

When you send a request you load it with cycles https://github.com/dfinity/examples/blob/master/motoko/exchange_rate/src/Main.mo#L277 I get this error because I haven’t loaded it with cylces An error happened during the call: 4: http_request request sent with 0 cycles, but 200_411_700_000 cycles are required. But what happens if you overload it. Does that carry over for additional request or you have to be very specific to only send what it requests for that http_request?

Found it here, section Pricing. It says: The cycles provided with the call must be sufficient for covering the cost of the request, excessive cycles are returned to the caller.

1 Like

As you mentioned that error, how did you solve it?

I deployed the eXchange Rate Canister locally using:
dfx deploy --specified-id uf6dk-hyaaa-aaaaq-qaaaq-cai xrc --with-cycles 10000000000
and I call its get_exchange_rate method with:
call_with_payment(self.xrc_id, "get_exchange_rate", (args,), 10_000_000_000)

However, I always get the error:
Asset: Asset { symbol: "ICP", class: Cryptocurrency }, Error: Failed to retrieve rate from Coinbase: http_request request sent with 0 cycles, but 5_589_600 cycles are required.

Why isn’t the XRC making the HTTP outcalls with the required cycles?

I download the WASM from: https://github.com/dfinity/exchange-rate-canister/releases/latest/download/xrc.wasm.gz

The XRC lives on a system subnet where making outcalls is free, so it’s not necessary for it to attach cycles. If you want it to work locally you have to set your local network to be a system subnet, too

2 Likes