1 Kings 17
1 Elijah the Tishbite, from Tishbe in Gilead, said to Ahab: “As the Lord, the God of Israel, lives, whom I serve, during these years there shall be no dew or rain except at my word.”
It is true that in 1 Kings 17, Elijah does not pray to God. However, the phrase "As the Lord lives" is very different from "Thus says the Lord." The latter begins a prophecy. The former is a statement by the speaker, not God. Elijah says, in effect, "by God, there will be no rain!"
James may apparently thought - or may have been aware of a rabbinical teaching - that Elijah's prophecy was a kind of curse in God's name, which is a negative prayer. This is echoed by Rashi in his commentary on this verse:
As Adonoy [the LORD] lives. Why was this placed here?.. Achov said to Eliyahu, “Is it possible that the student’s curse was fulfilled while Moshe our teacher’s curse was not fulfilled?
Rashi preserves an ancient tradition whereby Ahab challenged Elijah's prediction by referring to it a personal curse rather than a prophecy from God. Moses' personal blessings and curses were not always fulfilled, and Elijah is sure not as great as Moses. Whether this is a fact or not, this understanding is supported by Eliha's words: "during these years there shall be no dew or rain except at my word," which can again be interpreted as Elijah's word rather than God's.
Conclusion: James refers to Elijah's prayer rather than his prophecy, because although Elijah invoked God's name, he seems to make a declaration, an expression of an ardent wish or prayer. Because this was in accord with God's will, it did come true. James apparently thought that, in declaring the words "As the Lord lives," Elijah was earnestly praying to God rather than reporting what God had already predicted.