A prayer may be addressed to God (to God as such or, perhaps, to the Father) which is questioning, which is expressed in adversity, which may have a tome of perplexity, of need, and even of a query as to why the one praying is being treated in the way in which they find their situation.
But that is not 'despair'. Unbelieving despair does not pray at all. Unbelieving despair has already given up hope and cast off relationship with Deity.
Many, many instances can be seen in the psalms of someone crying out to God in the midst of truly terrible circumstances : persecution, battle, affliction, perplexity.
But the psalmists demonstrate a real, a deep, a very experienced, and a believing relationship with their God. And they call on Him because they know He will hear. They know He will listen. They know He will act - if is righteous to do so.
And that is the most important factor - if it is righteous to do so, that is to say if it is a matter of the righteousness of God (not the so-called 'rightness' which humanity commonly addresses).
We are told that the gospel is 'the power of God unto salvation for therein is the righteousness of God revealed, out of faith, unto faith' Romans 1:16. And at Golgotha, we see that righteousness being demonstrated by God upon his own Son.
We are told that 'he suffered for sins in his own body on the tree', 1 Peter 2:24 and, in that situation, God withdrew from the Sufferer in order to exact the righteous response of Deity to the sins which were laid upon the Sacrificial Lamb.
In his humanity, Jesus of Nazareth cried out, in anguish, sensing the departure of the presence of God. And, spontaneously, he quotes from words well known to him, from the twenty second psalm.
Matthew gives us the original Hebrew, 'Eli, Eli etc, of the psalm. Mark gives us the actual words in the Aramaic dialect, Eloi, Eloi etc, which Jesus spoke.
They are the poignant, anguished words of a son, of a worshipper, of a servant.
But there is no despair.
They were uttered in faith, for 'out of faith' was this righteousness of God demonstrated at Golgotha as the sacrifice was made, which, 'unto the faith' of the believer ensures justification from all things which the law of Moses was not able to justify, Acts 13:39.
Keep not silence, O God, hold not thy peace [Psalm 83:1]
Attend unto me and hear me; I mourn in my complaint and make a noise [Psalm 55:2]
Be merciful unto me, O God, for man would swallow me up [Psalm 56:1]
Cast me not away from thy presence and take not thy holy spirit from me [Psalm 51:11]
Awake, why sleepest thou, O Lord ? arise, cast us not off for ever [Psalm 44:23]
All references are from KJV.