include/entropic/interfaces/i_inference_backend.h

← API

include/entropic/interfaces/i_inference_backend.h

Functions

entropic_error_t entropic_inference_load(entropic_inference_backend_t backend, const char *config_json)

Load a model from config (COLD → WARM).

Load a model from config (COLD → WARM).

Parameters
  • backend — Backend handle.
  • config_json — JSON string of ModelConfig fields.
  • backend — Opaque backend handle from entropic_create_inference_backend().
  • config_json — JSON-serialized ModelConfig string.
Returns
  • ENTROPIC_OK on success, ENTROPIC_ERROR_LOAD_FAILED on failure.
  • ENTROPIC_OK on success, ENTROPIC_ERROR_LOAD_FAILED otherwise.

entropic_error_t entropic_inference_activate(entropic_inference_backend_t backend)

Activate model on GPU (WARM → ACTIVE).

If COLD, loads first (convenience path). Activate model on GPU (WARM → ACTIVE).

Parameters
  • backend — Backend handle.
  • backend — Opaque backend handle.
Returns
  • ENTROPIC_OK on success.
  • ENTROPIC_OK on success, ENTROPIC_ERROR_LOAD_FAILED otherwise.

entropic_error_t entropic_inference_deactivate(entropic_inference_backend_t backend)

Deactivate model (ACTIVE → WARM).

No-op if not ACTIVE. Deactivate model (ACTIVE → WARM).

Parameters
  • backend — Backend handle.
  • backend — Opaque backend handle.
Returns
  • ENTROPIC_OK.
  • ENTROPIC_OK on success, ENTROPIC_ERROR_INTERNAL on exception.

entropic_error_t entropic_inference_unload(entropic_inference_backend_t backend)

Unload model completely (→ COLD).

Releases all RAM + VRAM. Unload model completely (→ COLD).

Parameters
  • backend — Backend handle.
  • backend — Opaque backend handle.
Returns
  • ENTROPIC_OK.
  • ENTROPIC_OK on success, ENTROPIC_ERROR_INTERNAL on exception.

int entropic_inference_state(entropic_inference_backend_t backend)

Query model state (lock-free).

Query model state (lock-free).

Parameters
  • backend — Backend handle.
  • backend — Opaque backend handle.
Returns
  • State as int: 0=COLD, 1=WARM, 2=ACTIVE. Maps to entropic_model_state_t values.
  • Integer cast of ModelState (0=COLD, 1=WARM, 2=ACTIVE).

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).

Requires ACTIVE state. Returns ENTROPIC_ERROR_INVALID_STATE otherwise. Generate a response from messages (batch mode).

Parameters
  • backend — Backend handle.
  • messages_json — JSON array of message objects.
  • params_json — JSON object of GenerationParams fields.
  • result_json out — Output: JSON result string. Caller frees with entropic_inference_free().
  • backend — Opaque backend handle.
  • messages_json — JSON-serialized message list.
  • params_json — JSON-serialized GenerationParams.
  • result_json — Out-param: newly allocated result JSON (free with entropic_inference_free).
Returns
  • ENTROPIC_OK on success.
  • ENTROPIC_OK on success, result.error_code or ENTROPIC_ERROR_GENERATE_FAILED otherwise.

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.

gh#81 (v2.4.2): same contract as entropic_inference_generate plus a cancel-flag pointer. The pre-v2.4.2 batch path ran to natural stop with no way to honor an interrupt — observed ~60s lag on 13B models at default max_tokens. Setting *cancel_flag non-zero stops the decode within ~10ms + one token. Requires ACTIVE state. Generate a response (batch mode) with mid-decode cancellation. (gh#81, v2.4.2) See header for the full contract. Bridges the int* cancel flag to the backend's std::atomic<bool> via a CancelFlagBridge poller.

Parameters
  • backend — Backend handle.
  • messages_json — JSON array of message objects.
  • params_json — JSON object of GenerationParams fields.
  • result_json out — Output: JSON result string. Caller frees with entropic_inference_free().
  • cancel_flag — Pointer to int flag. Caller sets to non-zero to cancel. May be NULL if cancellation is not needed.
Returns
  • ENTROPIC_OK on success, ENTROPIC_ERROR_CANCELLED if cancelled.
  • ENTROPIC_OK on success, ENTROPIC_ERROR_CANCELLED if the cancel flag was raised mid-decode, ENTROPIC_ERROR_INVALID_ARGUMENT for a null backend/result, or the backend's error_code / ENTROPIC_ERROR_GENERATE_FAILED otherwise.

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.

Requires ACTIVE state. The on_token callback is invoked for each generated token. The token pointer is valid only for the duration of the callback — caller must copy if retention is needed. Generate with streaming token callback.

Parameters
  • backend — Backend handle.
  • messages_json — JSON array of message objects.
  • params_json — JSON object of GenerationParams fields.
  • on_token — Callback for each token. Must not call back into API.
  • user_data — Opaque pointer forwarded to on_token.
  • cancel_flag — Pointer to int flag. Caller sets to 1 to cancel. Checked between tokens — cancellation latency is one token. May be NULL if cancellation is not needed.
  • backend — Opaque backend handle.
  • messages_json — JSON-serialized message list.
  • params_json — JSON-serialized GenerationParams.
  • on_token — Callback fired per token (token bytes, length, user_data).
  • user_data — Opaque pointer passed to on_token.
  • cancel_flag — Optional pointer; setting *cancel_flag to non-zero stops generation.
Returns
  • ENTROPIC_OK on success, ENTROPIC_ERROR_CANCELLED if cancelled.
  • ENTROPIC_OK on success, result.error_code or ENTROPIC_ERROR_GENERATE_FAILED otherwise.

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.

Used by the router for digit-based classification. The prompt is passed directly to the model without any chat template formatting. Raw text completion without chat template.

Parameters
  • backend — Backend handle.
  • prompt — Raw prompt string.
  • params_json — Generation parameters as JSON.
  • result_json out — Output: JSON result string. Caller frees.
  • backend — Opaque backend handle.
  • prompt — Null-terminated prompt string.
  • params_json — JSON-serialized GenerationParams.
  • result_json — Out-param: newly allocated result JSON.
Returns
  • ENTROPIC_OK on success.
  • ENTROPIC_OK on success, result.error_code or ENTROPIC_ERROR_GENERATE_FAILED otherwise.

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.

Returns exact count when model is loaded (WARM or ACTIVE). Returns len/4 estimate when model is COLD. Count tokens in text using model's tokenizer.

Parameters
  • backend — Backend handle.
  • text — Text to tokenize.
  • text_len — Length of text in bytes.
  • backend — Opaque backend handle.
  • text — Pointer to UTF-8 text bytes.
  • text_len — Length of the text in bytes.
Returns
  • Token count (exact or estimated).
  • Exact token count when backend is WARM/ACTIVE, text_len/4 estimate on error.

void entropic_inference_destroy(entropic_inference_backend_t backend)

Destroy backend instance and free all resources.

Destroy backend instance and free all resources.

Parameters
  • backend — Backend handle. NULL is a safe no-op.
  • backend — Opaque backend handle (must not be used after this call).

void entropic_inference_free(void *ptr)

Free a string allocated by the inference backend.

Free a string allocated by the inference backend.

Parameters
  • ptr — Pointer returned by generate, complete, or similar. NULL is a safe no-op.
  • ptr — Pointer returned by a previous generate/complete call.

int entropic_inference_supports(entropic_inference_backend_t backend, int capability)

Query backend capability.

Parameters
  • backend — Backend handle.
  • capability — Capability enum value (see BackendCapability).
Returns
1 if supported, 0 if not.

uint32_t entropic_inference_capabilities(entropic_inference_backend_t backend)

Get all supported capabilities as bitmask.

Parameters
  • backend — Backend handle.
Returns
Bitmask where bit N corresponds to BackendCapability N.

char * entropic_inference_info(entropic_inference_backend_t backend)

Get backend metadata as JSON.

Parameters
  • backend — Backend handle.
Returns
JSON string of BackendInfo. Caller must free with entropic_inference_free().

entropic_error_t entropic_inference_save_state(entropic_inference_backend_t backend, int seq_id, void **buffer, size_t *buffer_size)

Save model state for a sequence.

Parameters
  • backend — Backend handle.
  • seq_id — Sequence identifier (0 for single-sequence).
  • buffer out — Output: pointer to state data. Caller frees with entropic_inference_free().
  • buffer_size out — Output: size of state data in bytes.
Returns
ENTROPIC_OK on success, ENTROPIC_ERROR_NOT_SUPPORTED if backend has neither KV_CACHE nor HIDDEN_STATE capability.

entropic_error_t entropic_inference_restore_state(entropic_inference_backend_t backend, int seq_id, const void *buffer, size_t buffer_size)

Restore model state for a sequence.

Parameters
  • backend — Backend handle.
  • seq_id — Sequence identifier.
  • buffer — State data from previous save_state call.
  • buffer_size — Size of state data.
Returns
ENTROPIC_OK on success, ENTROPIC_ERROR_STATE_INCOMPATIBLE if buffer is incompatible.

entropic_error_t entropic_inference_clear_state(entropic_inference_backend_t backend, int seq_id)

Clear/reset model state.

Parameters
  • backend — Backend handle.
  • seq_id — Sequence identifier, or -1 for all sequences.
Returns
ENTROPIC_OK on success.

entropic_error_t entropic_inference_generate_seq(entropic_inference_backend_t backend, int seq_id, const char *messages_json, const char *params_json, char **result_json)

Generate with explicit sequence ID.

Parameters
  • backend — Backend handle.
  • seq_id — Sequence identifier (0 for single-sequence backends).
  • messages_json — JSON string of messages.
  • params_json — JSON string of generation params.
  • result_json out — Output: JSON result string. Caller frees.
Returns
ENTROPIC_OK on success.

entropic_error_t entropic_inference_generate_streaming_seq(entropic_inference_backend_t backend, int seq_id, 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)

Streaming generation with explicit sequence ID.

Parameters
  • backend — Backend handle.
  • seq_id — Sequence identifier.
  • messages_json — JSON string of messages.
  • params_json — JSON string of generation params.
  • on_token — Callback for each token. Must not call back into API.
  • user_data — Opaque pointer forwarded to on_token.
  • cancel_flag — Pointer to int flag. Set to 1 to cancel. May be NULL.
Returns
ENTROPIC_OK on success, ENTROPIC_ERROR_CANCELLED if cancelled.

void entropic_inference_log_to_file(const char *path)

Redirect llama/ggml logs to a file.

Opens the file (truncating), redirects all llama.cpp and ggml log output to it. Call with NULL to silence logs entirely. Redirect llama/ggml logs to a file. First-call-wins under multi-handle (gh#58): a second handle whose canonical path differs is rejected with a warning rather than clobbering the live redirect. Same-path re-call truncates and reopens (preserves pre-v2.2.5 reset-on-recall behavior).

Parameters
  • path — Log file path (null-terminated), or NULL to silence.

void entropic_inference_log_silence(void)

Silence all llama/ggml log output.

Silence all llama/ggml log output.

Types

typedef struct entropic_inference_backend* entropic_inference_backend_t

Opaque handle to an inference backend instance.