By Katie Paul and Akash Sriram

(Reuters) -Meta Platforms Inc CEO Mark Zuckerberg said on Wednesday that AI was helping the company boost traffic to Facebook and Instagram and earn more in ad sales, as it forecast quarterly revenue well above analyst expectations.

Meta shares surged 12% in after hours trading, adding over $50 billion to its market value and continuing a rally in tech shares that started after Google parent Alphabet Inc and Microsoft Corp posted strong results on Tuesday.

Meta narrowed its cost outlook range for the year, saying expenses could be less than the company forecast in March, and also beat expectations for first-quarter profit and revenue, which rose for the first time in nearly a year.

The company, which has been slow to adopt AI-friendly hardware and software systems for its main business, has carried out several expensive overhauls to bolster its core business, including a massive project to upgrade AI capacity.

“At this point, we are no longer behind in building out our AI infrastructure,” Zuckerberg said on a conference call. “And to the contrary, we now have the capacity to do leading work in this space at scale.”

AI recommendations increased time spent on Instagram by 24% in the January-March quarter, Meta said.

“I think similar to Alphabet, a lot of Meta’s AI investments have gone into the advertiser side,” said James Cordwell, analyst at Atlantic Equities.

“So as a consumer we’re maybe not seeing the fruits of their labor in that area, but it certainly seems as if they are able to use more advanced algorithms to maintain a certain level of ad targeting.”

Meta has also kicked off an aggressive cost-cutting drive, with plans to eliminate 21,000 jobs and flatten its middle-management structure as it works towards Zuckerberg’s goal of turning 2023 into the “year of efficiency”.

The results indicated that austerity drive was “off to a stronger than expected start for Meta,” said Insider Intelligence principal analyst Debra Aho Williamson.

“In this economic environment—and after the disaster that was 2022—3% year over year revenue growth is an accomplishment. Meta’s strong guidance for Q2 revenue is another indicator that the company may be starting to come out of the woods.”

The social media giant faced a bruising 2022 as a pandemic-era e-commerce boom sputtered, while rivals like TikTok captured young users and Apple Inc’s privacy updates cut access to the user data around which it built its ads business.

COST CONTROL

Spending on the AI retooling has spiked the company’s capital expenditures, which came in slightly under expectations at $7.1 billion for the quarter. Analysts had forecast $7.2 billion in capital expenditures in the quarter, based on the company’s annual forecast of $30 billion to $33 billion, which it kept unchanged.

The company left open the possibility that it could increase capital expenditures as it builds products for generative AI, an emerging technology that can craft human-like writing, art and other content.

“Zuckerberg is well aware that his spending habits are being watched very carefully, and any renewed efforts to shift the budget to untested areas won’t go down well,” said Sophie Lund-Yates, lead equity analyst at Hargreaves Lansdown.

“That said, it’s very hard to penny-pinch your way to the top, leaving Meta walking a very fine line between keeping the lights on and making the future bright enough to excite investors.”

Meta said it continued to expect operating losses in its metaverse-oriented Reality Labs unit to increase in 2023. The company had been investing billions of dollars into the unit, which lost $13.7 billion last year.

Zuckerberg said he remained committed to the investments.

“A narrative has developed that we’re somehow moving away from focusing on the metaverse vision. I just want to say upfront: that’s not accurate,” he said. “We’ve been focusing on both AI and the metaverse for years now, and we will continue to focus on both.”

Meta narrowed its annual expenses forecast to between $86 billion and $90 billion, down from the $86 billion to $92 billion it had predicted in March, when it announced its second round of layoffs.

The company said its quarterly price per ad decreased 17% from a year earlier, while it expects current-quarter revenue between $29.5 billion and $32 billion, compared with analysts’ estimates of $29.53 billion, according to Refinitiv data.

Net profit for the first three months of the year fell to $2.20 per share from $2.72 a year earlier, but beat expectations of $2.03 a share.

Revenue for the first quarter rose 3% to $28.65 billion, beating an average estimate of $27.66 billion.

(Reporting by Katie Paul in New York and Akash Sriram in Bengaluru; Editing by Arun Koyyur and Deepa Babington)