#pragma once // The remaining public routes: embeddings, rerank, images, video, audio, // batches, files, containers, presets, server tools and public datasets, // decisions, and the auth / OAuth routes (PKCE code exchange). JSON bodies // are checked against the call table (calls.h). #include #include #include #include "openrouter/gateway.h" namespace molo::openrouter { class EmbeddingsService : public Endpoint { public: explicit EmbeddingsService(std::shared_ptr g) : Endpoint(std::move(g)) {} // model + input (string, or array of up to Caps::kMaxEmbeddingInputs). Json create(const Json& body) const; Json rerank(const std::string& model, const std::string& query, const std::vector& documents, std::optional top_n = std::nullopt) const; // The float vectors of an embeddings response (encoding_format float). static std::vector> vectors(const Json& response); }; class MediaService : public Endpoint { public: explicit MediaService(std::shared_ptr g) : Endpoint(std::move(g)) {} Json generate_image(const Json& body) const; // model + prompt Json submit_video(const Json& body) const; // model + prompt; async job (202) Json video_status(const std::string& job_id) const; llm::RawResponse video_content(const std::string& job_id, std::optional index = std::nullopt) const; llm::RawResponse speech(const Json& body) const; // model + input + voice; audio bytes Json transcribe(const Json& body) const; // model + input_audio Json decisions(const Json& body) const; // POST /api/alpha/decisions Json system_one(const Json& body) const; // POST /systemone }; class BatchesService : public Endpoint { public: explicit BatchesService(std::shared_ptr g) : Endpoint(std::move(g)) {} Json list(std::optional limit = std::nullopt, const std::string& after = "", const std::string& status = "") const; Json get(const std::string& id) const; // endpoint, model and requests (at most Caps::kMaxBatchRequests). Costs money. Json create(const Json& body) const; Json remove(const std::string& id) const; }; class FilesService : public Endpoint { public: explicit FilesService(std::shared_ptr g) : Endpoint(std::move(g)) {} Json list(std::optional limit = std::nullopt, const std::string& cursor = "") const; Json metadata(const std::string& file_id) const; llm::RawResponse content(const std::string& file_id) const; Json upload(const std::string& filename, const std::string& content_type, const std::string& data) const; Json remove(const std::string& file_id) const; Json container_files(const std::string& container_id, std::optional limit = std::nullopt, const std::string& after = "") const; Json container_file(const std::string& container_id, const std::string& file_id) const; llm::RawResponse container_file_content(const std::string& container_id, const std::string& file_id) const; Json promote_container_file(const std::string& container_id, const std::string& file_id) const; }; class PresetsService : public Endpoint { public: explicit PresetsService(std::shared_ptr g) : Endpoint(std::move(g)) {} Json list(std::optional offset = std::nullopt, std::optional limit = std::nullopt) const; Json get(const std::string& slug) const; Json versions(const std::string& slug, std::optional offset = std::nullopt, std::optional limit = std::nullopt) const; Json version(const std::string& slug, const std::string& version) const; // These three CREATE a preset from a request body of that skin (they do not run inference). Json create_from_chat(const std::string& slug, const Json& chat_body) const; Json create_from_messages(const std::string& slug, const Json& messages_body) const; Json create_from_responses(const std::string& slug, const Json& responses_body) const; }; // Server tool registry and public datasets. class CatalogService : public Endpoint { public: explicit CatalogService(std::shared_ptr g) : Endpoint(std::move(g)) {} Json tools(std::optional offset = std::nullopt, std::optional limit = std::nullopt, const std::string& api_format = "") const; Json tool(const std::string& name) const; Json benchmarks(const Query& query = {}) const; Json task_classifications(const std::string& window = "") const; Json app_rankings(const Query& query = {}) const; Json rankings_daily(const Query& query = {}) const; Json session_cost(const Query& query = {}) const; }; // PKCE (RFC 7636) helpers and the OAuth routes. struct PkcePair { std::string verifier; // 43..128 chars of [A-Za-z0-9-._~] std::string challenge; // base64url(SHA-256(verifier)), no padding static PkcePair from_verifier(const std::string& verifier); static PkcePair generate(); // verifier from the system CSPRNG }; class AuthService : public Endpoint { public: explicit AuthService(std::shared_ptr g) : Endpoint(std::move(g), KeyKind::kNone) {} // The browser URL the user visits: https://openrouter.ai/auth?callback_url=...&code_challenge=...&code_challenge_method=S256 static std::string authorization_url(const std::string& callback_url, const PkcePair& pkce); // POST /auth/keys: exchanges the code from the redirect for a user key. The // response `key` is a secret: never log it. Json exchange_code(const std::string& code, const std::string& verifier) const; // POST /auth/keys/code (needs the API key): creates an authorization code. Json create_code(const Json& body) const; Json jwks() const; // POST /oauth/token: workload identity token exchange (form encoded). Json exchange_token(const std::string& federation_policy_id, const std::string& subject_token, const std::string& subject_token_type) const; }; } // namespace molo::openrouter