We analyze the optimal licensing contract that a patentee provides for a cost reducing innovation to a set of firms competing in a downstream market. We study two alternative licensing regimes: (i) a combination of royalties on sales and flat fees and (ii) fixed fees only. The first contract depends on the degree of competition in the final good market: when competition is stronger, the patentee demands a higher royalty. We also show that, contrary to the literature, using fixed fees only is not optimal for the patentee when firms are heterogeneous or when there is product differentiation. The reason is that royalties allow the patent holder to soften competition in the final good market. Finally we show that even though a combination of royalties and fees allows for improved access to the technology, social welfare is lower compared with using fixed fees only.