feat(clients): openrouter: whole public API, spec-checked call table, chat model, demo
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
// Route: POST /ai/openrouter/chat (paid: dry run unless confirm)
|
||||
#include "support/Assert.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
Fixture f;
|
||||
auto post = [&](const std::string& body) { return f.client->post("/ai/openrouter/chat", body, "application/json"); };
|
||||
auto dry = post("{\"model\":\"openai/gpt-4o:nitro\",\"prompt\":\"hi\",\"provider\":{\"sort\":\"price\"},\"models\":[\"anthropic/claude-3.5-sonnet\"]}");
|
||||
check(dry.status == 200 && contains(dry.body, "\"dry_run\":true"), "chat is a dry run");
|
||||
check(contains(dry.body, "\"sort\":\"price\"") && contains(dry.body, "\"max_tokens\":64"), "dry run shows routing and the token cap");
|
||||
check(post("{\"model\":\"openai/gpt-4o\",\"prompt\":\"hi\",\"confirm\":true}").status == 503, "confirmed chat without key is 503");
|
||||
check(post("{\"prompt\":\"hi\"}").status == 422, "missing model 422");
|
||||
check(post("{\"model\":\"nonsense\",\"prompt\":\"hi\"}").status == 422, "bad model id 422");
|
||||
check(post("{\"model\":\"a/b:bogus\",\"prompt\":\"hi\"}").status == 422, "unknown variant 422");
|
||||
check(post("{\"model\":\"a/b\"}").status == 422, "missing prompt 422");
|
||||
check(post("{\"model\":\"a/b\",\"prompt\":\"x\",\"max_tokens\":100000}").status == 422, "token cap 422");
|
||||
check(post("{\"model\":\"a/b\",\"prompt\":\"x\",\"provider\":{\"quantizations\":[\"fp99\"]}}").status == 422, "bad provider 422");
|
||||
check(post("{\"model\":\"a/b\",\"prompt\":\"x\",\"provider\":[1]}").status == 422, "provider must be an object 422");
|
||||
check(post("oops").status == 422, "invalid JSON 422");
|
||||
check(f.client->get("/ai/openrouter/chat").status == 405, "get is 405");
|
||||
return finish("ai/openrouter/chat");
|
||||
}
|
||||
Reference in New Issue
Block a user