inference_c_api.cpp

src/inference/inference_c_api.cpp

@file inference_c_api.cpp @brief C API wrappers for InferenceBackend.

Owners: @tvanfossen

entropic_inference_activate

entropic_error_t entropic_inference_activate(entropic_inference_backend_t backend)

Activate model on GPU (WARM → ACTIVE).

src/inference/inference_c_api.cpp:238

Show on the map →

Called by TEST_CASE

Calls activate, to_backend

Source · 11 lines
ENTROPIC_EXPORT entropic_error_t entropic_inference_activate(
    entropic_inference_backend_t backend)
{
    if (!backend) { return ENTROPIC_ERROR_INVALID_ARGUMENT; }
    try {
        return to_backend(backend)->activate() ? ENTROPIC_OK : ENTROPIC_ERROR_LOAD_FAILED;
    } catch (const std::exception& e) {
        logger->error("inference_activate exception: {}", e.what());
        return ENTROPIC_ERROR_LOAD_FAILED;
    }
}
Activity · 3 steps
lines 241–241◇ if (!backend)lines 241–241return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 242–247try { return to_backend(backend)->activate() ? ENTROPIC_OK : ENTROPIC_ERROR_LOAD_FAILED; } catch (const std::exception& e) { logger->error("inference_activate exception: {}", e.what()); return ENTROPIC_ERROR_LOAD_FAILED; }
ENTROPIC_EXPORT entropic_error_t entropic_inference_activate(entropic_inference_backend_t backend)

Plugin C API: promote backend from WARM to ACTIVE (GPU load).

src/inference/inference_c_api.cpp:238

Show on the map →

Called by TEST_CASE

Calls activate, to_backend

Source · 11 lines
ENTROPIC_EXPORT entropic_error_t entropic_inference_activate(
    entropic_inference_backend_t backend)
{
    if (!backend) { return ENTROPIC_ERROR_INVALID_ARGUMENT; }
    try {
        return to_backend(backend)->activate() ? ENTROPIC_OK : ENTROPIC_ERROR_LOAD_FAILED;
    } catch (const std::exception& e) {
        logger->error("inference_activate exception: {}", e.what());
        return ENTROPIC_ERROR_LOAD_FAILED;
    }
}
Activity · 3 steps
lines 241–241◇ if (!backend)lines 241–241return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 242–247try { return to_backend(backend)->activate() ? ENTROPIC_OK : ENTROPIC_ERROR_LOAD_FAILED; } catch (const std::exception& e) { logger->error("inference_activate exception: {}", e.what()); return ENTROPIC_ERROR_LOAD_FAILED; }

Requirements

REQ-INFER-017

entropic_inference_complete

entropic_error_t entropic_inference_complete(entropic_inference_backend_t backend, const char *prompt, const char *params_json, char **result_json)

Raw text completion without chat template.

src/inference/inference_c_api.cpp:519

Show on the map →

Called by TEST_CASE

Calls alloc_string, complete, parse_params_json, serialize_result_json, to_backend

Source · 19 lines
ENTROPIC_EXPORT entropic_error_t entropic_inference_complete(
    entropic_inference_backend_t backend,
    const char* prompt,
    const char* params_json,
    char** result_json)
{
    if (!backend || !prompt || !result_json) {
        return ENTROPIC_ERROR_INVALID_ARGUMENT;
    }
    try {
        auto params = parse_params_json(params_json);
        auto result = to_backend(backend)->complete(prompt, params);
        *result_json = alloc_string(serialize_result_json(result));
        return result.ok() ? ENTROPIC_OK : result.error_code;
    } catch (const std::exception& e) {
        logger->error("inference_complete exception: {}", e.what());
        return ENTROPIC_ERROR_GENERATE_FAILED;
    }
}
Activity · 3 steps
lines 525–525◇ if (!backend || !prompt || !result_json)lines 526–526return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 528–536try { auto params = parse_params_json(params_json); auto result = to_backend(backend)->complete(prompt, params); *result_json = alloc_string(serialize_result_json(result)); return result.ok() ? ENTROPIC_OK : result.error_code; } catch (const std::exception& e) { logger->error("inference_complete exception: {}", e.what()); return ENTROPIC_ERROR_GENERATE_FAILED; }
ENTROPIC_EXPORT entropic_error_t entropic_inference_complete(entropic_inference_backend_t backend, const char *prompt, const char *params_json, char **result_json)

Plugin C API: raw text completion without chat template.

src/inference/inference_c_api.cpp:519

Show on the map →

Called by TEST_CASE

Calls alloc_string, complete, parse_params_json, serialize_result_json, to_backend

Source · 19 lines
ENTROPIC_EXPORT entropic_error_t entropic_inference_complete(
    entropic_inference_backend_t backend,
    const char* prompt,
    const char* params_json,
    char** result_json)
{
    if (!backend || !prompt || !result_json) {
        return ENTROPIC_ERROR_INVALID_ARGUMENT;
    }
    try {
        auto params = parse_params_json(params_json);
        auto result = to_backend(backend)->complete(prompt, params);
        *result_json = alloc_string(serialize_result_json(result));
        return result.ok() ? ENTROPIC_OK : result.error_code;
    } catch (const std::exception& e) {
        logger->error("inference_complete exception: {}", e.what());
        return ENTROPIC_ERROR_GENERATE_FAILED;
    }
}
Activity · 3 steps
lines 525–525◇ if (!backend || !prompt || !result_json)lines 526–526return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 528–536try { auto params = parse_params_json(params_json); auto result = to_backend(backend)->complete(prompt, params); *result_json = alloc_string(serialize_result_json(result)); return result.ok() ? ENTROPIC_OK : result.error_code; } catch (const std::exception& e) { logger->error("inference_complete exception: {}", e.what()); return ENTROPIC_ERROR_GENERATE_FAILED; }

Requirements

REQ-INFER-004

entropic_inference_count_tokens

int entropic_inference_count_tokens(entropic_inference_backend_t backend, const char *text, size_t text_len)

Count tokens in text using model's tokenizer.

src/inference/inference_c_api.cpp:548

Show on the map →

Called by TEST_CASE

Calls count_tokens, to_backend

Source · 15 lines
ENTROPIC_EXPORT int entropic_inference_count_tokens(
    entropic_inference_backend_t backend,
    const char* text,
    size_t text_len)
{
    // v2.3.10: null guards. text=nullptr is a real misuse (caller
    // owes us bytes). Returning 0 keeps the contract simple (no
    // tokens to count when there's no string).
    if (!backend || !text) { return 0; }
    try {
        return to_backend(backend)->count_tokens(std::string(text, text_len));
    } catch (...) {
        return static_cast<int>(text_len) / 4;
    }
}
Activity · 3 steps
lines 556–556◇ if (!backend || !text)lines 556–556return 0;lines 557–561try { return to_backend(backend)->count_tokens(std::string(text, text_len)); } catch (...) { return static_cast<int>(text_len) / 4; }
ENTROPIC_EXPORT int entropic_inference_count_tokens(entropic_inference_backend_t backend, const char *text, size_t text_len)

Plugin C API: count tokens for a text span (exact when loaded, estimate when COLD).

src/inference/inference_c_api.cpp:548

Show on the map →

Called by TEST_CASE

Calls count_tokens, to_backend

Source · 15 lines
ENTROPIC_EXPORT int entropic_inference_count_tokens(
    entropic_inference_backend_t backend,
    const char* text,
    size_t text_len)
{
    // v2.3.10: null guards. text=nullptr is a real misuse (caller
    // owes us bytes). Returning 0 keeps the contract simple (no
    // tokens to count when there's no string).
    if (!backend || !text) { return 0; }
    try {
        return to_backend(backend)->count_tokens(std::string(text, text_len));
    } catch (...) {
        return static_cast<int>(text_len) / 4;
    }
}
Activity · 3 steps
lines 556–556◇ if (!backend || !text)lines 556–556return 0;lines 557–561try { return to_backend(backend)->count_tokens(std::string(text, text_len)); } catch (...) { return static_cast<int>(text_len) / 4; }

Requirements

REQ-INFER-019

entropic_inference_deactivate

entropic_error_t entropic_inference_deactivate(entropic_inference_backend_t backend)

Deactivate model (ACTIVE → WARM).

src/inference/inference_c_api.cpp:257

Show on the map →

Called by TEST_CASE

Calls deactivate, to_backend

Source · 12 lines
ENTROPIC_EXPORT entropic_error_t entropic_inference_deactivate(
    entropic_inference_backend_t backend)
{
    if (!backend) { return ENTROPIC_ERROR_INVALID_ARGUMENT; }
    try {
        to_backend(backend)->deactivate();
        return ENTROPIC_OK;
    } catch (const std::exception& e) {
        logger->error("inference_deactivate exception: {}", e.what());
        return ENTROPIC_ERROR_INTERNAL;
    }
}
Activity · 3 steps
lines 260–260◇ if (!backend)lines 260–260return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 261–267try { to_backend(backend)->deactivate(); return ENTROPIC_OK; } catch (const std::exception& e) { logger->error("inference_deactivate exception: {}", e.what()); return ENTROPIC_ERROR_INTERNAL; }
ENTROPIC_EXPORT entropic_error_t entropic_inference_deactivate(entropic_inference_backend_t backend)

Plugin C API: demote backend from ACTIVE to WARM (release GPU).

src/inference/inference_c_api.cpp:257

Show on the map →

Called by TEST_CASE

Calls deactivate, to_backend

Source · 12 lines
ENTROPIC_EXPORT entropic_error_t entropic_inference_deactivate(
    entropic_inference_backend_t backend)
{
    if (!backend) { return ENTROPIC_ERROR_INVALID_ARGUMENT; }
    try {
        to_backend(backend)->deactivate();
        return ENTROPIC_OK;
    } catch (const std::exception& e) {
        logger->error("inference_deactivate exception: {}", e.what());
        return ENTROPIC_ERROR_INTERNAL;
    }
}
Activity · 3 steps
lines 260–260◇ if (!backend)lines 260–260return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 261–267try { to_backend(backend)->deactivate(); return ENTROPIC_OK; } catch (const std::exception& e) { logger->error("inference_deactivate exception: {}", e.what()); return ENTROPIC_ERROR_INTERNAL; }

Requirements

REQ-INFER-017

entropic_inference_destroy

void entropic_inference_destroy(entropic_inference_backend_t backend)

Destroy backend instance and free all resources.

src/inference/inference_c_api.cpp:570

Show on the map →

Called by TEST_CASE

Calls to_backend

Source · 5 lines
ENTROPIC_EXPORT void entropic_inference_destroy(
    entropic_inference_backend_t backend)
{
    delete to_backend(backend);
}
Activity · 1 steps
lines 573–573delete to_backend(backend);
ENTROPIC_EXPORT void entropic_inference_destroy(entropic_inference_backend_t backend)

Plugin C API: destroy the backend and free its resources.

src/inference/inference_c_api.cpp:570

Show on the map →

Called by TEST_CASE

Calls to_backend

Source · 5 lines
ENTROPIC_EXPORT void entropic_inference_destroy(
    entropic_inference_backend_t backend)
{
    delete to_backend(backend);
}
Activity · 1 steps
lines 573–573delete to_backend(backend);

Requirements

REQ-INFER-017

entropic_inference_generate

entropic_error_t entropic_inference_generate(entropic_inference_backend_t backend, const char *messages_json, const char *params_json, char **result_json)

Generate a response from messages (batch mode).

src/inference/inference_c_api.cpp:317

Show on the map →

Called by TEST_CASE

Calls alloc_string, generate, parse_messages_json, parse_params_json, serialize_result_json, to_backend

Source · 23 lines
ENTROPIC_EXPORT entropic_error_t entropic_inference_generate(
    entropic_inference_backend_t backend,
    const char* messages_json,
    const char* params_json,
    char** result_json)
{
    if (!backend || !result_json) {
        return ENTROPIC_ERROR_INVALID_ARGUMENT;
    }
    logger->info("C API: inference_generate");
    try {
        auto msgs = entropic::parse_messages_json(messages_json);
        auto params = parse_params_json(params_json);
        auto result = to_backend(backend)->generate(msgs, params);
        *result_json = alloc_string(serialize_result_json(result));
        logger->info("C API: inference_generate -> {}",
                     result.ok() ? "ok" : "error");
        return result.ok() ? ENTROPIC_OK : result.error_code;
    } catch (const std::exception& e) {
        logger->error("inference_generate exception: {}", e.what());
        return ENTROPIC_ERROR_GENERATE_FAILED;
    }
}
Activity · 4 steps
lines 323–323◇ if (!backend || !result_json)lines 324–324return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 326–326logger->info("C API: inference_generate");lines 327–338try { auto msgs = entropic::parse_messages_json(messages_json); auto params = parse_params_json(params_json); auto result = to_backend(backend)->generate(msgs, params); *result_json = alloc_string(serialize_result_json(result)); logger->info("C API: inference_generate -> {}", result.ok() ? "ok" : "error"); return result.ok() ? ENTROPIC_OK : result.error_code; } catch (const std::exception& e) { logger->error("inference_generate exception: {}", e.what()); return ENTROPIC_ERROR_GENERATE_FAILED; }
ENTROPIC_EXPORT entropic_error_t entropic_inference_generate(entropic_inference_backend_t backend, const char *messages_json, const char *params_json, char **result_json)

Plugin C API: blocking generation returning full result.

src/inference/inference_c_api.cpp:317

Show on the map →

Called by TEST_CASE

Calls alloc_string, generate, parse_messages_json, parse_params_json, serialize_result_json, to_backend

Source · 23 lines
ENTROPIC_EXPORT entropic_error_t entropic_inference_generate(
    entropic_inference_backend_t backend,
    const char* messages_json,
    const char* params_json,
    char** result_json)
{
    if (!backend || !result_json) {
        return ENTROPIC_ERROR_INVALID_ARGUMENT;
    }
    logger->info("C API: inference_generate");
    try {
        auto msgs = entropic::parse_messages_json(messages_json);
        auto params = parse_params_json(params_json);
        auto result = to_backend(backend)->generate(msgs, params);
        *result_json = alloc_string(serialize_result_json(result));
        logger->info("C API: inference_generate -> {}",
                     result.ok() ? "ok" : "error");
        return result.ok() ? ENTROPIC_OK : result.error_code;
    } catch (const std::exception& e) {
        logger->error("inference_generate exception: {}", e.what());
        return ENTROPIC_ERROR_GENERATE_FAILED;
    }
}
Activity · 4 steps
lines 323–323◇ if (!backend || !result_json)lines 324–324return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 326–326logger->info("C API: inference_generate");lines 327–338try { auto msgs = entropic::parse_messages_json(messages_json); auto params = parse_params_json(params_json); auto result = to_backend(backend)->generate(msgs, params); *result_json = alloc_string(serialize_result_json(result)); logger->info("C API: inference_generate -> {}", result.ok() ? "ok" : "error"); return result.ok() ? ENTROPIC_OK : result.error_code; } catch (const std::exception& e) { logger->error("inference_generate exception: {}", e.what()); return ENTROPIC_ERROR_GENERATE_FAILED; }

Requirements

REQ-ABI-001 REQ-INFER-001

entropic_inference_generate_streaming

entropic_error_t entropic_inference_generate_streaming(entropic_inference_backend_t backend, const char *messages_json, const char *params_json, void(*on_token)(const char *token, size_t len, void *user_data), void *user_data, int *cancel_flag)

Generate with streaming token callback.

src/inference/inference_c_api.cpp:476

Show on the map →

Called by TEST_CASE

Calls generate_streaming, ok, on_token, parse_messages_json, parse_params_json, to_backend

Source · 32 lines
ENTROPIC_EXPORT entropic_error_t entropic_inference_generate_streaming(
    entropic_inference_backend_t backend,
    const char* messages_json,
    const char* params_json,
    void (*on_token)(const char* token, size_t len, void* user_data),
    void* user_data,
    int* cancel_flag)
{
    if (!backend || !on_token) {
        return ENTROPIC_ERROR_INVALID_ARGUMENT;
    }
    try {
        auto msgs = entropic::parse_messages_json(messages_json);
        auto params = parse_params_json(params_json);
        std::atomic<bool> cancel{false};

        auto callback = [on_token, user_data, cancel_flag, &cancel]
            (std::string_view token) {
                on_token(token.data(), token.size(), user_data);
                if (cancel_flag && *cancel_flag) {
                    cancel.store(true, std::memory_order_release);
                }
            };

        auto result = to_backend(backend)->generate_streaming(
            msgs, params, callback, cancel);
        return result.ok() ? ENTROPIC_OK : result.error_code;
    } catch (const std::exception& e) {
        logger->error("inference_generate_streaming exception: {}", e.what());
        return ENTROPIC_ERROR_GENERATE_FAILED;
    }
}
Activity · 3 steps
lines 484–484◇ if (!backend || !on_token)lines 485–485return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 487–506try { auto msgs = entropic::parse_messages_json(messages_json); auto params = parse_params_json(params_json); std::atomic<bool> cancel{false}; auto callback = [on_token, user_data, cancel_flag, &cancel] (std::string_view token) { on_token(token.data(), token.size(), user_data); if (cancel_flag && *cancel_flag) { cancel.store(true, std::memory_order_release); } }; auto result = to_backend(backend)->generate_streaming( msgs, params, callback, cancel); return result.ok() ? ENTROPIC_OK : result.error_code; } catch (const std::exception& e) { logger->error("inference_generate_streaming exception: {}", e.what()); return ENTROPIC_ERROR_GENERATE_FAILED; }
ENTROPIC_EXPORT entropic_error_t entropic_inference_generate_streaming(entropic_inference_backend_t backend, const char *messages_json, const char *params_json, void(*on_token)(const char *token, size_t len, void *user_data), void *user_data, int *cancel_flag)

Plugin C API: streaming generation with token callback and cancel flag.

src/inference/inference_c_api.cpp:476

Show on the map →

Called by TEST_CASE

Calls generate_streaming, ok, on_token, parse_messages_json, parse_params_json, to_backend

Source · 32 lines
ENTROPIC_EXPORT entropic_error_t entropic_inference_generate_streaming(
    entropic_inference_backend_t backend,
    const char* messages_json,
    const char* params_json,
    void (*on_token)(const char* token, size_t len, void* user_data),
    void* user_data,
    int* cancel_flag)
{
    if (!backend || !on_token) {
        return ENTROPIC_ERROR_INVALID_ARGUMENT;
    }
    try {
        auto msgs = entropic::parse_messages_json(messages_json);
        auto params = parse_params_json(params_json);
        std::atomic<bool> cancel{false};

        auto callback = [on_token, user_data, cancel_flag, &cancel]
            (std::string_view token) {
                on_token(token.data(), token.size(), user_data);
                if (cancel_flag && *cancel_flag) {
                    cancel.store(true, std::memory_order_release);
                }
            };

        auto result = to_backend(backend)->generate_streaming(
            msgs, params, callback, cancel);
        return result.ok() ? ENTROPIC_OK : result.error_code;
    } catch (const std::exception& e) {
        logger->error("inference_generate_streaming exception: {}", e.what());
        return ENTROPIC_ERROR_GENERATE_FAILED;
    }
}
Activity · 3 steps
lines 484–484◇ if (!backend || !on_token)lines 485–485return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 487–506try { auto msgs = entropic::parse_messages_json(messages_json); auto params = parse_params_json(params_json); std::atomic<bool> cancel{false}; auto callback = [on_token, user_data, cancel_flag, &cancel] (std::string_view token) { on_token(token.data(), token.size(), user_data); if (cancel_flag && *cancel_flag) { cancel.store(true, std::memory_order_release); } }; auto result = to_backend(backend)->generate_streaming( msgs, params, callback, cancel); return result.ok() ? ENTROPIC_OK : result.error_code; } catch (const std::exception& e) { logger->error("inference_generate_streaming exception: {}", e.what()); return ENTROPIC_ERROR_GENERATE_FAILED; }

Requirements

REQ-ABI-001 REQ-INFER-005

entropic_inference_generate_with_cancel

entropic_error_t entropic_inference_generate_with_cancel(entropic_inference_backend_t backend, const char *messages_json, const char *params_json, char **result_json, int *cancel_flag)

Generate a response (batch mode) with mid-decode cancellation.

src/inference/inference_c_api.cpp:437

Show on the map →

Called by TEST_CASE

Calls alloc_string, flag, generate, parse_messages_json, parse_params_json, serialize_result_json, to_backend

Source · 26 lines
ENTROPIC_EXPORT entropic_error_t entropic_inference_generate_with_cancel(
    entropic_inference_backend_t backend,
    const char* messages_json,
    const char* params_json,
    char** result_json,
    int* cancel_flag)
{
    if (!backend || !result_json) {
        return ENTROPIC_ERROR_INVALID_ARGUMENT;
    }
    logger->info("C API: inference_generate_with_cancel");
    try {
        auto msgs = entropic::parse_messages_json(messages_json);
        auto params = parse_params_json(params_json);
        CancelFlagBridge bridge(cancel_flag);
        auto result = to_backend(backend)->generate(
            msgs, params, bridge.flag());
        *result_json = alloc_string(serialize_result_json(result));
        logger->info("C API: inference_generate_with_cancel -> {}",
                     result.ok() ? "ok" : "error");
        return result.ok() ? ENTROPIC_OK : result.error_code;
    } catch (const std::exception& e) {
        logger->error("inference_generate_with_cancel exception: {}", e.what());
        return ENTROPIC_ERROR_GENERATE_FAILED;
    }
}
Activity · 4 steps
lines 444–444◇ if (!backend || !result_json)lines 445–445return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 447–447logger->info("C API: inference_generate_with_cancel");lines 448–461try { auto msgs = entropic::parse_messages_json(messages_json); auto params = parse_params_json(params_json); CancelFlagBridge bridge(cancel_flag); auto result = to_backend(backend)->generate( msgs, params, bridge.flag()); *result_json = alloc_string(serialize_result_json(result)); logger->info("C API: inference_generate_with_cancel -> {}", result.ok() ? "ok" : "error"); return result.ok() ? ENTROPIC_OK : result.error_code; } catch (const std::exception& e) { logger->error("inference_generate_with_cancel exception: {}", e.what()); return ENTROPIC_ERROR_GENERATE_FAILED; }
ENTROPIC_EXPORT entropic_error_t entropic_inference_generate_with_cancel(entropic_inference_backend_t backend, const char *messages_json, const char *params_json, char **result_json, int *cancel_flag)

Plugin C API: batch generation with mid-decode cancel.

src/inference/inference_c_api.cpp:437

Show on the map →

Called by TEST_CASE

Calls alloc_string, generate, parse_messages_json, parse_params_json, serialize_result_json, to_backend

Source · 26 lines
ENTROPIC_EXPORT entropic_error_t entropic_inference_generate_with_cancel(
    entropic_inference_backend_t backend,
    const char* messages_json,
    const char* params_json,
    char** result_json,
    int* cancel_flag)
{
    if (!backend || !result_json) {
        return ENTROPIC_ERROR_INVALID_ARGUMENT;
    }
    logger->info("C API: inference_generate_with_cancel");
    try {
        auto msgs = entropic::parse_messages_json(messages_json);
        auto params = parse_params_json(params_json);
        CancelFlagBridge bridge(cancel_flag);
        auto result = to_backend(backend)->generate(
            msgs, params, bridge.flag());
        *result_json = alloc_string(serialize_result_json(result));
        logger->info("C API: inference_generate_with_cancel -> {}",
                     result.ok() ? "ok" : "error");
        return result.ok() ? ENTROPIC_OK : result.error_code;
    } catch (const std::exception& e) {
        logger->error("inference_generate_with_cancel exception: {}", e.what());
        return ENTROPIC_ERROR_GENERATE_FAILED;
    }
}
Activity · 4 steps
lines 444–444◇ if (!backend || !result_json)lines 445–445return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 447–447logger->info("C API: inference_generate_with_cancel");lines 448–461try { auto msgs = entropic::parse_messages_json(messages_json); auto params = parse_params_json(params_json); CancelFlagBridge bridge(cancel_flag); auto result = to_backend(backend)->generate( msgs, params, bridge.flag()); *result_json = alloc_string(serialize_result_json(result)); logger->info("C API: inference_generate_with_cancel -> {}", result.ok() ? "ok" : "error"); return result.ok() ? ENTROPIC_OK : result.error_code; } catch (const std::exception& e) { logger->error("inference_generate_with_cancel exception: {}", e.what()); return ENTROPIC_ERROR_GENERATE_FAILED; }

Requirements

REQ-INFER-001

entropic_inference_load

entropic_error_t entropic_inference_load(entropic_inference_backend_t backend, const char *config_json)

Load a model from config (COLD → WARM).

src/inference/inference_c_api.cpp:207

Show on the map →

Called by TEST_CASE

Calls load, parse_config_json, to_backend

Source · 23 lines
ENTROPIC_EXPORT entropic_error_t entropic_inference_load(
    entropic_inference_backend_t backend,
    const char* config_json)
{
    // v2.3.10: null-handle guard. Pre-v2.3.10 to_backend(nullptr)
    // returned nullptr and the next ->load() dereferenced it, taking
    // the whole process down with SIGSEGV. The plugin ABI is the
    // load-bearing boundary for misuse; rejecting null with a clean
    // error code is safer than crashing.
    if (!backend) { return ENTROPIC_ERROR_INVALID_ARGUMENT; }
    logger->info("C API: inference_load");
    try {
        auto config = parse_config_json(config_json);
        auto rc = to_backend(backend)->load(config)
            ? ENTROPIC_OK : ENTROPIC_ERROR_LOAD_FAILED;
        logger->info("C API: inference_load -> {}",
                     static_cast<int>(rc));
        return rc;
    } catch (const std::exception& e) {
        logger->error("inference_load exception: {}", e.what());
        return ENTROPIC_ERROR_LOAD_FAILED;
    }
}
Activity · 4 steps
lines 216–216◇ if (!backend)lines 216–216return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 217–217logger->info("C API: inference_load");lines 218–228try { auto config = parse_config_json(config_json); auto rc = to_backend(backend)->load(config) ? ENTROPIC_OK : ENTROPIC_ERROR_LOAD_FAILED; logger->info("C API: inference_load -> {}", static_cast<int>(rc)); return rc; } catch (const std::exception& e) { logger->error("inference_load exception: {}", e.what()); return ENTROPIC_ERROR_LOAD_FAILED; }
ENTROPIC_EXPORT entropic_error_t entropic_inference_load(entropic_inference_backend_t backend, const char *config_json)

Plugin C API: load a model into the inference backend.

src/inference/inference_c_api.cpp:207

Show on the map →

Called by TEST_CASE

Calls load, parse_config_json, to_backend

Source · 23 lines
ENTROPIC_EXPORT entropic_error_t entropic_inference_load(
    entropic_inference_backend_t backend,
    const char* config_json)
{
    // v2.3.10: null-handle guard. Pre-v2.3.10 to_backend(nullptr)
    // returned nullptr and the next ->load() dereferenced it, taking
    // the whole process down with SIGSEGV. The plugin ABI is the
    // load-bearing boundary for misuse; rejecting null with a clean
    // error code is safer than crashing.
    if (!backend) { return ENTROPIC_ERROR_INVALID_ARGUMENT; }
    logger->info("C API: inference_load");
    try {
        auto config = parse_config_json(config_json);
        auto rc = to_backend(backend)->load(config)
            ? ENTROPIC_OK : ENTROPIC_ERROR_LOAD_FAILED;
        logger->info("C API: inference_load -> {}",
                     static_cast<int>(rc));
        return rc;
    } catch (const std::exception& e) {
        logger->error("inference_load exception: {}", e.what());
        return ENTROPIC_ERROR_LOAD_FAILED;
    }
}
Activity · 4 steps
lines 216–216◇ if (!backend)lines 216–216return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 217–217logger->info("C API: inference_load");lines 218–228try { auto config = parse_config_json(config_json); auto rc = to_backend(backend)->load(config) ? ENTROPIC_OK : ENTROPIC_ERROR_LOAD_FAILED; logger->info("C API: inference_load -> {}", static_cast<int>(rc)); return rc; } catch (const std::exception& e) { logger->error("inference_load exception: {}", e.what()); return ENTROPIC_ERROR_LOAD_FAILED; }

Requirements

REQ-INFER-017

entropic_inference_log_silence

void entropic_inference_log_silence(void)

Silence all llama/ggml log output.

src/inference/inference_c_api.cpp:717

Show on the map →

Called by TEST_CASE, entropic_create, entropic_destroy

Calls ggml_log_silence_locked

Source · 4 lines
void entropic_inference_log_silence(void) {
    std::lock_guard lk(s_ggml_log_mu);
    ggml_log_silence_locked();
}
Activity · 2 steps
lines 718–718std::lock_guard lk(s_ggml_log_mu);lines 719–719ggml_log_silence_locked();
void entropic_inference_log_silence(void)

Silence all llama/ggml output.

src/inference/inference_c_api.cpp:717

Show on the map →

Called by TEST_CASE, entropic_create, entropic_destroy

Calls ggml_log_silence_locked

Source · 4 lines
void entropic_inference_log_silence(void) {
    std::lock_guard lk(s_ggml_log_mu);
    ggml_log_silence_locked();
}
Activity · 2 steps
lines 718–718std::lock_guard lk(s_ggml_log_mu);lines 719–719ggml_log_silence_locked();

Flows

entropic_inference_state

int entropic_inference_state(entropic_inference_backend_t backend)

Query model state (lock-free).

src/inference/inference_c_api.cpp:297

Show on the map →

Called by TEST_CASE

Calls state, to_backend

Source · 9 lines
ENTROPIC_EXPORT int entropic_inference_state(
    entropic_inference_backend_t backend)
{
    // v2.3.10: null-handle returns COLD (0) — the safest "I don't
    // own anything" answer. Callers gating activation on state should
    // treat null + COLD identically anyway.
    if (!backend) { return static_cast<int>(ENTROPIC_MODEL_STATE_COLD); }
    return static_cast<int>(to_backend(backend)->state());
}
Activity · 3 steps
lines 303–303◇ if (!backend)lines 303–303return static_cast<int>(ENTROPIC_MODEL_STATE_COLD);lines 304–304return static_cast<int>(to_backend(backend)->state());
ENTROPIC_EXPORT int entropic_inference_state(entropic_inference_backend_t backend)

Plugin C API: query current lifecycle state (lock-free).

src/inference/inference_c_api.cpp:297

Show on the map →

Called by TEST_CASE

Calls state, to_backend

Source · 9 lines
ENTROPIC_EXPORT int entropic_inference_state(
    entropic_inference_backend_t backend)
{
    // v2.3.10: null-handle returns COLD (0) — the safest "I don't
    // own anything" answer. Callers gating activation on state should
    // treat null + COLD identically anyway.
    if (!backend) { return static_cast<int>(ENTROPIC_MODEL_STATE_COLD); }
    return static_cast<int>(to_backend(backend)->state());
}
Activity · 3 steps
lines 303–303◇ if (!backend)lines 303–303return static_cast<int>(ENTROPIC_MODEL_STATE_COLD);lines 304–304return static_cast<int>(to_backend(backend)->state());

Requirements

REQ-INFER-018

entropic_inference_unload

entropic_error_t entropic_inference_unload(entropic_inference_backend_t backend)

Unload model completely (→ COLD).

src/inference/inference_c_api.cpp:277

Show on the map →

Called by TEST_CASE

Calls to_backend, unload

Source · 12 lines
ENTROPIC_EXPORT entropic_error_t entropic_inference_unload(
    entropic_inference_backend_t backend)
{
    if (!backend) { return ENTROPIC_ERROR_INVALID_ARGUMENT; }
    try {
        to_backend(backend)->unload();
        return ENTROPIC_OK;
    } catch (const std::exception& e) {
        logger->error("inference_unload exception: {}", e.what());
        return ENTROPIC_ERROR_INTERNAL;
    }
}
Activity · 3 steps
lines 280–280◇ if (!backend)lines 280–280return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 281–287try { to_backend(backend)->unload(); return ENTROPIC_OK; } catch (const std::exception& e) { logger->error("inference_unload exception: {}", e.what()); return ENTROPIC_ERROR_INTERNAL; }
ENTROPIC_EXPORT entropic_error_t entropic_inference_unload(entropic_inference_backend_t backend)

Plugin C API: release the loaded model (transition to COLD).

src/inference/inference_c_api.cpp:277

Show on the map →

Called by TEST_CASE

Calls to_backend, unload

Source · 12 lines
ENTROPIC_EXPORT entropic_error_t entropic_inference_unload(
    entropic_inference_backend_t backend)
{
    if (!backend) { return ENTROPIC_ERROR_INVALID_ARGUMENT; }
    try {
        to_backend(backend)->unload();
        return ENTROPIC_OK;
    } catch (const std::exception& e) {
        logger->error("inference_unload exception: {}", e.what());
        return ENTROPIC_ERROR_INTERNAL;
    }
}
Activity · 3 steps
lines 280–280◇ if (!backend)lines 280–280return ENTROPIC_ERROR_INVALID_ARGUMENT;lines 281–287try { to_backend(backend)->unload(); return ENTROPIC_OK; } catch (const std::exception& e) { logger->error("inference_unload exception: {}", e.what()); return ENTROPIC_ERROR_INTERNAL; }

Requirements

REQ-INFER-017