http.request.do() get error from openRouter ! #25076
-
import net.http fn main() {
}error message : |
Beta Was this translation helpful? Give feedback.
Answered by
gechandesu
Aug 9, 2025
Replies: 1 comment 1 reply
-
Works for me. Details
import net.http
fn main() {
url := 'https://openrouter.ai/api/v1/chat/completions'
model := 'deepseek/deepseek-r1-0528:free'
question := 'What is the meaning of life?'
// data := '{ "model": "${model}", "prompt": "${question}" } '
// data := '{ "model": "${model}", "messages": { "prompt": "${question}" } }'
data := '{ "model": "${model}", "messages": [ { "role": "user", "content": "${question}" } ], "temperature": 0.7 }'
println(data)
mut req := http.new_request(.post, url, data)
req.user_agent = 'Mozilla/5.0 Firefox'
req.add_header(.content_type, 'application/json')
req.add_header(.authorization, 'Bearer sk-or-v1-xxxxxxxxxxxx')
println(req)
resp := req.do()!
println(resp)
println(['res.body:', resp.body])
} Result:
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
luyuan1975
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works for me.
Details