C API
Embed StrataFlow in your own application through its stable C ABI in strataflow.h.
StrataFlow exposes a stable C ABI in include/strataflow/strataflow.h. The CLI uses it, and so can your application or a language binding. Everything below the API (the weight store, scheduler and predictor) is private C++.
Example
#include <stdio.h>
#include <strataflow/strataflow.h>
static int on_token(const char *text, void *user_data) {
(void)user_data;
fputs(text, stdout);
fflush(stdout);
return 0; /* return non-zero to stop early */
}
int main(void) {
sf_context_params cp = sf_context_default_params();
cp.model_path = "/models/mixtral.strata";
cp.cache_budget = 4ull << 30; /* at most 4 GiB of resident experts */
sf_context *ctx = NULL;
sf_status st = sf_context_create(&cp, &ctx);
if (st != SF_OK) {
fprintf(stderr, "load failed: %s\n", sf_status_str(st));
return 1;
}
sf_session *session = NULL;
sf_session_create(ctx, &session);
sf_sampling_params sp = sf_sampling_default_params();
sp.temperature = 0.0f; /* greedy */
sp.max_tokens = 64;
st = sf_generate(session, "The city of", &sp, on_token, NULL);
sf_runtime_stats stats;
if (sf_session_stats(session, &stats) == SF_OK) { /* inspect memory and timing */ }
sf_session_free(session);
sf_context_free(ctx);
return st == SF_OK ? 0 : 1;
}Lifecycle
| Function | Purpose |
|---|---|
sf_context_default_params() | Safe defaults: automatic planning, CPU backend |
sf_context_create(params, &ctx) | Create an engine and load a model. On failure ctx stays NULL. |
sf_session_create(ctx, &session) | Open a session, which owns a KV cache (one conversation) |
sf_generate(session, prompt, sampling, cb, user_data) | Generate a completion, streaming UTF-8 pieces to cb. Blocks until done. |
sf_session_stats(session, &stats) | Runtime statistics |
sf_describe_plan(ctx, buf, size) | Write the placement plan as text |
sf_session_free, sf_context_free | Release resources |
sf_version(), sf_status_str(status) | Version string and error messages |
Context parameters
Prop
Type
expert_slots and async_prefetch are applied through process-wide settings read when a context is created. Don't
create contexts with different values for them from several threads at once; create them one after another.
Sampling parameters
Prop
Type
Status codes
| Code | Value | Meaning |
|---|---|---|
SF_OK | 0 | Success |
SF_ERR_INVALID_ARGUMENT | 1 | A parameter is invalid |
SF_ERR_FILE_NOT_FOUND | 2 | The model file doesn't exist |
SF_ERR_UNSUPPORTED | 3 | The feature or model isn't supported yet |
SF_ERR_OUT_OF_MEMORY | 4 | Not enough memory |
SF_ERR_IO | 5 | A read failed |
SF_ERR_MODEL_LOAD | 6 | The model couldn't be loaded |
SF_ERR_RUNTIME | 7 | A runtime error, including a target RAM ceiling that can't be met |
Linking
Build StrataFlow as a shared library by defining STRATAFLOW_SHARED; the header exports symbols with the right visibility on Windows, Linux and macOS.