Four deployment approaches
| Criterion | On-device | Self-hosted | External API | Hybrid |
|---|---|---|---|---|
| Offline operation | Possible | Possible on local network | Usually no | Path-dependent |
| Scaling | User hardware | Operator | Provider and limits | Both environments |
| Weight control | License-dependent | License-dependent | Service-dependent | Model-dependent |
| Maintenance | App and device | Entire inference stack | Integration and provider | Both stacks |
| Data | Inspect connections | Inspect infrastructure | Inspect agreement | Inspect routing policy |
Inference uses a trained model; it is not training. On-device inference executes on the user's computer or phone. Self-hosting means operating the inference runtime on owned or rented infrastructure. A provider API (application programming interface) delegates execution to a managed service. A local model can expose an API too; the terms are not opposites.
Downloadable weights do not automatically satisfy the OSI definition of open-source AI or grant unrestricted commercial use. Check the exact model license, use restrictions, redistribution, derivative model terms and component licenses. Running downloaded weights is not equivalent to training your own model from scratch. [1]
Hardware, memory and inference engines
Local inference depends on RAM or VRAM, memory bandwidth, and supported operators and numerical formats. Ideal weight storage in bytes is N × b / 8, with N parameters and b bits per parameter. An 8B model needs 16 GB at BF16 or an ideal 4 GB at 4 bits (decimal GB). Real formats may include scales and tensors at higher precision. [2]
The KV cache stores attention keys and values for processed context. With conventional attention, 32 layers, 8 KV heads, head dimension 128, 4096 tokens and BF16, it uses 2 × 32 × 8 × 128 × 4096 × 2 = 536,870,912 bytes, or 512 MiB per independent context. Eight contexts require 4 GiB before overhead, assuming no sharing. Other architectures, KV quantization and sharing change this result. Allow additional memory for buffers, activations, the operating system and allocation overhead. [2][3]
llama.cpp supports different hardware and quantization formats; Ollama simplifies local execution, and vLLM provides concurrent serving mechanisms and server metrics. Match the engine to the model, hardware and required capabilities such as tool calls. Do not assume every combination works. [2][3][4]
Examples for local evaluation include Google Gemma 4 E2B IT (its model card lists Apache 2.0) and OpenAI gpt-oss-20b (about 21 billion total parameters, 3.6 billion active). These are candidates, not a ranking. Check the exact revision, precision, chat template and measured memory usage. [12][13]
For mixture-of-experts (MoE) models, active parameters per token do not determine the memory required for all weights. gpt-oss-20b has 20.9 billion total parameters and about 3.6 billion active per token; its publisher uses the Harmony format and releases weights under Apache 2.0. Do not estimate memory from 3.6 billion parameters or assume every tensor uses the same precision. Check the actual artifact and engine configuration. [13][17]
Privacy, security and compliance
Local inference does not make the entire data path local. Telemetry, external embeddings, search, plugins, backups and agent tools can transmit information off-device. Inspect outbound traffic, disable unnecessary cloud features, restrict network access to the server and test offline operation after downloading all artifacts. [4]
OpenAI API's no-training default does not mean no retention: standard abuse monitoring logs may be retained for up to 30 days, subject to exceptions. Zero Data Retention (ZDR) depends on eligibility and features. Anthropic documents separate retention arrangements by service and agreed configuration. Gemini terms distinguish paid and unpaid services, with specific rules for the EEA, Switzerland and UK. For paid services Google states that content is not used to improve products but permits limited safety logging. Documentation checked on 3 December 2026. [5][6][7]
Distinguish request content, application state and security logs: store=false alone is not a no-retention guarantee. Gemini’s current terms apply paid-service data-use rules to unpaid services in the EEA, Switzerland and the UK as well. Before sending sensitive data, check the exact model, feature, region, contract and project configuration. [5][6][7]
Under the GDPR, establish controller and processor roles, lawful basis and purpose, minimization, retention, deletion and any transfers outside the EEA. Where applicable, check processing agreements, security measures and Chapter V of the GDPR. EU data location does not establish compliance by itself; local servers also need protection. Encrypt connections, isolate tenants and cache keys, enforce permissions, verify artifact provenance and never automatically execute model-generated commands. [8]
Ollama lets you disable cloud features by setting OLLAMA_NO_CLOUD=1 and restarting the server. Check the logs for confirmation, then test the application without external network access. This setting does not block connections from other application components or replace a firewall. [4]
The Gemini API terms effective March 23, 2026 require Paid Services when making API clients available to users in the EEA, Switzerland or the United Kingdom. Distinguish the data-use rules for unpaid quota from permission to offer such an application. Check audience and use restrictions as well. If personal data processing is likely to result in high risk, assess the requirement for a data protection impact assessment before processing (GDPR Article 35). [7][8]
A shared vLLM process does not provide complete tenant isolation. The v0.34.0 documentation warns that --api-key alone does not protect all endpoints. Block direct access and expose only necessary operations through an authenticated gateway. A tenant-scoped secret cache_salt mitigates specific prefix-cache risks but is not an isolation boundary. Where tenant isolation is required, use separate instances and appropriate network and process boundaries. [16]
API and self-hosting costs
For token billing, cost = (I × pI + O × pO) / 1,000,000, where I and O are billed input and output tokens and pI and pO are prices per million. Account separately for cache reads and writes, tools, multimodal inputs, reasoning tokens according to provider billing rules, retries and storage. Batch processing and long-context thresholds can change rates. [9][10][11]
Actual pricing snapshot checked on 3 December 2026: OpenAI GPT-6.2 Sol, Standard, short context, USD 2 per million input tokens and USD 10 per million output tokens. For 100,000 calls with 2000 billed input and 500 output tokens each, token costs alone total USD 900 (400 + 500). GPT-6.2 Astra at USD 8 and 40 costs USD 3600. Cache, taxes, tools and additional calls are excluded. This is a price snapshot, not a quality comparison or price forecast. [9]
Self-hosting costs include depreciation or rental, electricity, cooling, storage, networking, monitoring, support, updates, backups and spare capacity. Electricity example: average whole-device wall power of 0.25 kW for 300 hours yields 75 kWh; at an assumed PLN 1.20/kWh this costs PLN 90. This is neither a current tariff nor a hardware measurement. Do not count electricity twice when it is included in rental.
For another provider, the price list checked on December 3, 2026 gives Gemini 4 Neon Standard rates of USD 3 per million input tokens and USD 15 per million output tokens (including thinking tokens). With the same billed token counts as above, the monthly cost is USD 1,350 (600 + 750). Actual token counts can differ due to tokenization, reasoning and tools. This is not a quality comparison or a comparison of actual bills. [11]
Break-even and cost per accepted result
| Tasks | API | Self-hosting |
|---|---|---|
| 10 000 | 90 | 610 |
| 75 000 | 675 | 675 |
| 100 000 | 900 | 700 |
Assume hypothetically an API costs USD 0.009 per task, while self-hosting costs USD 600 monthly plus USD 0.001 per task. With equal quality and sufficient capacity, break-even is 600 / (0.009 − 0.001) = 75,000 monthly tasks. At 100,000 tasks the API costs USD 900 and hosting USD 700. At 10,000 tasks the costs are USD 90 and 610. These are assumptions, not hosting offers or measurements.
More generally, with API cost per task a, self-hosting variable cost v and fixed hosting cost F, break-even Q = F / (a − v) exists for F > 0 and a > v, assuming constant rates and no API fixed cost. If a ≤ v, traffic alone will not make hosting cheaper. If the API also has fixed costs, compare the difference in fixed costs. Run sensitivity analysis for rates, utilization and quality.
Cost per accepted result is total cost divided by the number of tasks meeting predefined criteria. With 100,000 tasks, 95% API acceptance and 70% self-hosted acceptance, the costs are USD 900 / 95,000 ≈ 0.00947 and USD 700 / 70,000 = 0.01, respectively. Cheaper infrastructure can lose on quality. Include manual corrections, retries and error costs. Break-even changes when extra servers are required or marginal cost changes with load.
When acceptance rates differ, compare cost per accepted result: a/qA for the API and (F/Q + v)/qL for hosting. qA and qL are positive fractions of accepted tasks (from 0 to 1). For F > 0, equality occurs at Q = F × qA / (a × qL − v × qA) when the denominator is positive. With the previous assumptions and 95% versus 70% acceptance, the threshold is about 106,542 tasks, not 75,000. Hosting is cheaper per accepted result from 106,543 whole tasks if costs, acceptance rates and capacity remain constant. This is a hypothetical model, not a profitability forecast.
Performance, availability and quality
Measure time to first token (TTFT), inter-token latency, end-to-end time, throughput and p50/p95 under realistic concurrency. Separate prompt processing (prefill) from token generation (decode). Local execution avoids remote model calls but weak hardware or queues may increase latency. APIs have limits, latency variability and network dependencies. [3]
Build a representative test set: languages, context lengths, hard tasks, absent evidence, malicious inputs and tool calls. Record weight revision, quantization, tokenizer, chat template, instructions, budgets and configuration. Compare quality at equivalent requirements, not necessarily equal token counts because tokenizers differ. Separate cold starts from warmed servers and test load spikes. Report successful tasks within service-level objectives (SLOs) or agreements (SLAs), not just tokens per second. [3]
For 100,000 tasks producing 500 tokens each over 300 available hours, aggregate output throughput must average about 46.3 tokens/s (50 million / 1,080,000 s). This is a minimum average, not single-stream speed. Allow for prefill, peaks and headroom. Replication increases capacity; splitting a model across devices can accommodate larger weights but requires communication. [14]
Do not expose a self-hosted inference server publicly without authentication and limits. Put it behind a protected gateway, bound request size and volume, separate environments and log without unnecessary user content. Monitor queues, memory and rejected requests; plan security updates, rollback and recovery tests. [3][14]
Hybrid architecture and portability
Hybrid decision flow
- Determine permissions and data class.
- Exclude prohibited processing locations.
- Select a model meeting requirements.
Validate output and account for the task.
If no eligible model remains, decline execution or escalate to a human.
A model gateway should separate access policy, routing, limits, cost accounting and provider adapters. First determine the permitted data-processing location, then select a model that can satisfy quality and latency requirements. Escalate to an external API only if data policy permits it. Do not rely solely on self-reported model confidence.
A common API does not guarantee feature parity: message roles, streaming, output schemas, tool calls and billing can differ. Test provider contracts, explicitly mark unsupported capabilities and use bounded backoff retries for transient errors. External actions require idempotency controls; a repeated inference request must not inadvertently repeat a payment or message delivery. Maintain versioned configurations and rollback capability.
In a hybrid system, account for escalation too. If each of 100,000 tasks costs USD 0.001 locally and 20% require an additional API call costing USD 0.009, variable cost is USD 100 + 180 = 280. Adding USD 600 in fixed costs gives USD 880. Do not assume the acceptance rate is a weighted average of model acceptance rates: escalated tasks may be harder, and the complete path must be evaluated.
How to choose
RAG vs Fine-tuning vs Long Context
For a low-volume, irregular prototype with no prohibition on data transfer, test a managed API if it meets requirements. For offline work, data restrictions or a stable on-device task, test a local model. For predictable load and an operations team, consider self-hosting only after measuring capacity, cost and quality. Hybrid design helps when tasks differ in requirements; justify its additional complexity with measurements.
Do not confuse inference location with knowledge delivery. Retrieval-augmented generation (RAG), fine-tuning and long context can work in either deployment when supported by the model and infrastructure. Set acceptance criteria before deployment, pilot the system, run security and overload tests, and compare cost per accepted result. Verify contingency plans for provider or own-server unavailability. Re-evaluate after changes to weights, runtime, rates or data policy.
For a separate comparison of knowledge-delivery methods, see the related POLPROG article. [15]
