Encounted "InstructionCountLimitExceededError" while querying an external api in Shopify Function

Hello,

I have a Shopify Extension App for transforming customer cart items using the expand operation. My intention is to retrieve some information from an external graphql api via the urql client in order to extend my products appropriately.

Upon making a request I will encounter the following error

Function export "run" failed to execute with error: InstructionCountLimitExceededError

Is there a way to increase the limit or an alternative solution Shopify provides that will enable me to make a graphql query to an external source within my Cart Transform Function?

My function is written in Typescript

Thanks

The Instruction you typed “CountLimitExceededError” typically occurs when a function exceeds the execution limit set by Shopify’s runtime. Unfortunately, Shopify imposes strict limits on function execution to ensure performance and scalability, and these limits cannot be increased manually.

What I think you can just do is:
Move External Calls Outside the Function
Shopify Functions are designed to be fast and deterministic, which means they don’t allow direct external API calls. Instead, you can:

Use Shopify’s Cart and Checkout validation API or webhooks to fetch the required data ahead of time and store it in Shopify’s metafields or a dedicated app proxy.

I wish this help in one way or the other.

Awesome. Thank you very much for your reply. Using the cart/create webhook may be the solution i need. Just to follow through, are you aware of any implications one might encounter or rather should be watchful of when using this method to extend cart pricing at checkout? E.g.

  • Will this impact the checkout and payment flow?

  • Will the extended price update the base price of the product on the store?

I assume the answer to these will likely be no, but i’d like to hear your perspective as well.

You’re absolutely right—using the cart/create webhook can be a good approach for fetching external data to extend cart pricing. However, I think there are a few key considerations to keep in mind:

First one is that: Webhooks operate asynchronously, meaning they do not block the checkout process. However, any pricing adjustments must be reflected before the customer proceeds to checkout, as Shopify locks in cart prices at that stage.

And the second point i thought of is that If your webhook depends on an external API response, ensure it’s optimized to minimize delays. Otherwise, customers might see outdated or incorrect pricing.

What do you think about that also?

You have raised some very good points, thank you. I’ll take them into consideration during development. My data source is a graphql api powered by Urql which has caching capabilities built in, this should help with responsiveness.

Your second point on outdated pricing can also be mitigated by perhaps designing a flow to update pricing at low traffic times. This may require more research from me, but your help has been tremendous. Thank you.

Converting it Rust definitely help me increase how big the cart could be before failure (by 3x in one case), but there is always going to be an upper limit.