/* junction/opencode.h — opencode serve as a first-class endpoint. * * An opencode serve speaks a session-oriented API: * * POST /api/session -> {"data":{"id":"ses_…"}} * POST /api/session//model {"model":{"id":…,"providerID":…}} * POST /api/session//prompt {"text":"…"} * GET /api/session//message -> {"data":[{type,…},…]} * DELETE /api/session/ * * There is no /v1/chat/completions. This module translates one into the other, so a * client that speaks OpenAI never has to know it is talking to opencode. */ #ifndef JUNCTION_OPENCODE_H #define JUNCTION_OPENCODE_H #include /* Runs one complete chat completion through opencode. * * base "http://127.0.0.1:4096" (no /v1 suffix; the paths above are absolute) * user,pass HTTP Basic credentials; opencode accepts "opencode:" * model the model to ask for. May be "provider/id", "id", or empty for the * server's default. A trailing "#variant" selects an opencode model * variant (its reasoning-effort selector). * req_body the OpenAI request body as received. reasoning_effort, * reasoning.effort, variant and thinking.type=disabled are carried into * the session model's variant; other generation options have no slot in * the session prompt API. * out_body receives a malloc'ed OpenAI response body (caller frees) * * Returns 0 on success, -1 on failure with a reason in err. */ int j_opencode_chat(const char *base, const char *user, const char *pass, const char *model, const char *req_body, char **out_body, size_t *out_len, double timeout_s, char *err, size_t errlen); /* Lists the models an opencode server knows, as an OpenAI /v1/models body. * Same ownership rules as above. */ int j_opencode_models(const char *base, const char *user, const char *pass, char **out_body, size_t *out_len, double timeout_s, char *err, size_t errlen); #endif /* JUNCTION_OPENCODE_H */