#I keep getting an HTTP response error 400 Bad Request when using a HttpClient in C#.

5 messages · Page 1 of 1 (latest)

keen pelican
#

I've added my api key as the Authorization header (eg. "Bearer sk-or-v1-3...") and everything else seems fine. The endpoint is "https://openrouter.ai/api/v1/chat/completions". I've serialised the Request object fine using a Prompt property, etc. Any ideas?

Here's what the Request object looks like, serialised: "{"messages":null,"prompt":"You are an expert fiction writer. Give me 10 story ideas for a cozy mystery.","model":"mistralai/mistral-7b-instruct","logit_bias":null,"max_tokens":null,"response_format":null,"seed":null,"stop":null,"stream":null,"temperature":0.7,"top_p":0.7,"top_k":null,"frequency_penalty":null,"presence_penalty":null,"tools":null,"tool_choice":null,"transforms":null,"models":null,"route":null}"

brittle sage
#

hm - try omitting all the null value'd keys

keen pelican
#

Thanks for the response and taking the time to look at this. I don't think its that. I use JSON serialisation a lot and it has never been an issue with other services.

keen pelican
#

@brittle sage - I take it all back; it works when I ignore properties that are null. Never had to do this with other REST services I've used. Suppose it depends on how they're configured.
Many thanks for your suggestion as it prompted me to investigate it further! Cheers, mate!

brittle sage
#

There's an error message that says which parameter can't accept a null value