Tesla has confirmed it’s in talks with the Chinese government to open a factory in the Shanghai region, as the company aims to fulfill a promise by its CEO Elon Musk to produce 500,000 cars a year by 2018.

The official confirmation, which was provided in an emailed statement, puts to rest months of speculation that Tesla was going to open a factory in the world’s largest automotive market.

The electric automaker and energy storage company said it expects to “more clearly define its plans for producing electric vehicles in China by the end of the year.” The news of the talks was first reported by Reuters.

Tesla says it plans to open a factory in the world’s largest automotive market

“Tesla is deeply committed to the Chinese market, and we continue to evaluate potential manufacturing sites around the globe to serve the local markets,” the company said in an emailed statement. “While we expect most of our production to remain in the US, we do need to establish local factories to ensure affordability for the markets they serve.”

It isn’t immediately clear if Tesla would take on a local partner as part of a joint venture in China, a long-held requirement for foreign companies wanting to set up shop there.

Today, Tesla produces all of its cars in the US. However, if the company hopes to increase its production to 500,000 vehicles a year — that’s a six-fold increase over 2016 numbers — and reach more consumers in Europe and Asia, it will have to open factories closer to those customers.

A factory in China should theoretically help Tesla sell more cars there. Today, the company has to pay a 25 percent tariff on the cars it imports, which in turn, raises the price tag of the vehicles.

A factory in China should theoretically help Tesla sell more cars there

Rumors of an impending deal with China heated up in April after Musk made an unexpected visit to the country and met with Vice Premier Wang Yang, a high-ranking government official. Just a month before, Tesla disclosed that Chinese internet giant Tencent Holdings bought a 5 percent stake in the company.

Tesla had a rough start in China. Sales fell short in 2014 despite an aggressive effort to open service centers and stores, roll out its fast-charging stations known as Superchargers, and kick off a hiring spree that led to more than 600 staff.

However, Tesla turned its sluggish sales around and had a breakthrough year in 2016 with sales topping $1 billion — three times higher than 2015, according to documents filed with the US Securities and Exchange Commission. While the US is still Tesla’s largest market, China has vast potential thanks to the growing percentage of car ownership and the country’s effort to improve air quality and encourage sales of electric and hybrid vehicles.