Migrating from the OpenAI API to self-hosted Ollama

Teams moving off a hosted model API need to change endpoints, choose open models that meet their quality bar and shift traffic without breaking users. This page explains what the migration involves, what drives its effort, and when a partner is worth bringing in.

On this page

Migrating from the OpenAI API to self-hosted Ollama: what the work involves

The migration is mainly an endpoint, model and evaluation project, not a rewrite. If your application already calls a hosted model API through an OpenAI client library, most of the change is pointing that client at a local Ollama server, choosing an open model that can replace the hosted one for each task, and proving the outputs are good enough before traffic moves. For most teams, keeping the migration in-house is workable when one engineering group owns the application and has time to run evaluations. A partner makes more sense when the work spans several applications, needs formal compliance evidence, or must be finished alongside a contract deadline for the hosted API.

The usual triggers are data residency (prompts and documents must stay in your own cloud account, data center or air-gapped network), cost predictability (spend becomes hardware and staff time instead of per-token charges that move with usage), vendor dependence (you want the option to change models without rewriting clients), and air-gapped needs where no external API is reachable at all. Confirm which of these actually drives the decision, because each one changes the model choice and the network design.

Plan for an authentication difference before anything else. The local Ollama API at localhost:11434 does not require an API key, so a client that sends a Bearer token to the local server will work, but the token is not checked. Direct cloud inference at ollama.com/api and ollama.com/v1 does require an API key sent as a Bearer token, so any code path that can fall back to the cloud must carry credentials and be reviewed. Inventory every place your application reads an API key, including environment variables, secrets managers and CI configuration, and decide which calls must never leave your network. Check the current behavior in the Ollama API authentication documentation before you rely on it, since it governs whether a stray key can send prompts to a hosted service.

What an Ollama migration from the OpenAI API includes

A migration moves each application from a hosted model API to a self-hosted Ollama server without breaking what users depend on. The cards below are the work packages and the deliverables that close them, in the order they usually run. Each feature your applications use must be checked against the Ollama API before the scope is fixed.

Inventory of OpenAI calls

List every call your applications make to the OpenAI API, including chat completions, embeddings, tool use, streaming responses and structured output. For each feature, check whether the Ollama API supports the same request shape and response fields, and record gaps such as unsupported parameters or differing error formats. This check decides the scope, so confirm it against the current Ollama documentation before quoting work.

Ollama FAQ

Ollama installed and bound

Install Ollama on the chosen hardware and set the bind address deliberately. Ollama listens on 127.0.0.1 port 11434 by default, so clients on other machines need a changed address through OLLAMA_HOST and a proxy in front of it. Record the model storage path with OLLAMA_MODELS, and confirm that cloud features are turned off with OLLAMA_NO_CLOUD=1 if the data must stay local.

Client configuration changes

Change each application to point its base URL at the Ollama endpoint and replace the hosted API key with the settings the local server expects. Ollama's local API does not require authentication, so any access control must be added in front of it. Keep the change in configuration rather than code where possible, so the same build can point at either provider during the cutover.

Replacement model shortlist

Select open models that match the tasks your applications perform, such as chat, summarization, extraction, embeddings or code. Size each candidate against the memory and GPU available on the target hardware, and record its license and provenance. Expect that no single open model matches every hosted model on every task, so the shortlist should name a model for each task category.

Evaluation set and results

Build a test set from real, anonymized prompts drawn from production logs, with expected outputs or grading rules for each task. Run the same set against the hosted model and each shortlisted open model, then score quality, format compliance, latency and failure rates. Results should be written down with the date, model tag and Ollama version used, so a later comparison is valid.

Cutover plan and runbook

Define a gradual cutover that routes a small share of traffic to Ollama, widens it in steps, and returns traffic to the hosted API on a set trigger. Document the rollback steps, the owners, the monitoring signals and the criteria for each step. The runbook is the handover document that keeps the migrated system operable after the migration team leaves.

Traffic shifts in stages, with the hosted API as the fallback

The diagram starts at the application or a small routing layer that decides, per request, whether to send traffic to the hosted API or to Ollama. The Ollama path crosses a reverse proxy inside the client network before reaching the Ollama server on its internal address, because Ollama's local API has no authentication of its own. Logging sits on both paths so output and latency can be compared. Check that failed Ollama calls fall back cleanly to the hosted API and that the proxy, not the Ollama port, is the only way in from other hosts.

Gradual cutover routes a share of requests to Ollama, with hosted API fallback and logging on both paths.

What drives the effort and duration of the migration

This table lists the factors that change how much work a move from a hosted OpenAI API to self-hosted Ollama takes, why each one matters and how to keep it down. Use it to see which answers your team must give before a fixed-scope quote can be written.

DriverWhy it changes effortHow to keep it down
Number of applications and call sitesEach application and each direct SDK call needs its base URL, model name and error handling changed, and each one needs testing.Route calls through one internal client library so the endpoint and model mapping are changed in one place.
OpenAI features used per applicationChat completions, streaming, tool calling, JSON output, embeddings and file or assistant features vary in how closely Ollama's OpenAI-compatible endpoint matches them. Each gap adds design and test work.Inventory the features each call site uses and drop or simplify unused ones before migration starts.
Quality bar and evaluation set sizeA larger, stricter evaluation set takes longer to build, run and score, and disagreements on acceptable output extend review cycles.Agree the acceptance criteria per use case first and keep the evaluation set to representative prompts that the business has signed off.
Number of replacement modelsEach task type may need a different open model, and each model needs its own evaluation, prompt tuning and resource planning.Map use cases to as few candidate models as possible and retire tasks that do not justify a separate model.
Available hardware and GPU sizingModel size, quantization, context length and concurrency decide whether existing hardware is enough or new GPUs must be bought and installed.Test candidate models on a representative machine early and size from measured memory and throughput rather than assumptions.
Environments (development, test, production)Each environment needs its own Ollama server, model copies, configuration and access settings, and each change must be promoted through them.Keep configuration identical across environments and differ only in hostnames and secrets, and script model pulls.
Compliance evidence requiredAssessors may ask for model provenance, access logs, data handling records and change history, which must be collected and kept current.Confirm the evidence list with your compliance team before design so logging and documentation are built in, not added later.
Client teams that must change configurationEvery team that owns an application must review, change and deploy its settings, and coordinate release windows with others.Publish one migration guide and a shared configuration template, and move teams in waves rather than all at once.

The phases of an Ollama migration and what each one delivers

The sequence moves a team from calls to a hosted model API to a self-hosted Ollama endpoint in controlled steps. Each phase closes with a written output and a go or no-go decision, so traffic only moves once the replacement has been checked against current behavior.

  1. Inventory every API call and dependency

    The application owner and platform engineers list every service that calls the hosted API, including the model names, prompt sizes, streaming use, tool or function calling, embeddings, rate limits and the data each call sends. The output is a call inventory with a named owner for each service and a list of features that depend on specific model behavior. The phase closes when the inventory is reviewed and signed off by the people who own those services.

  2. Size hardware and install Ollama

    Platform engineers choose the host or hosts from the model shortlist requirements, install Ollama on Linux, macOS, Windows or Docker, and set the model storage directory with OLLAMA_MODELS if the default location is not suitable. They confirm the server listens only where intended, since it binds to 127.0.0.1 on port 11434 by default. The phase closes when a test model loads and answers a request through the local API, and the team has recorded the installed version.

  3. Shortlist replacement open models

    The team matches each inventoried use case to one or more candidate open models, based on the task, the context length needed, the memory available and any license terms the organization must accept. Candidates are pulled onto the test host and assigned a version or tag that will be recorded in the runbook. The output is a short list of models per use case with a stated reason for each. The phase closes when the product owner and the security reviewer accept the list.

  4. Evaluate outputs against current API results

    The team builds a fixed test set from real but de-identified prompts in the call inventory and runs it against the hosted API and each candidate. Reviewers score answers against criteria written before the run, covering correctness, format compliance, refusals, latency and tool-call accuracy. The output is a comparison report with pass rates per use case and a list of prompts where the replacement fails. The phase closes with a decision per use case: adopt the model, adjust prompts, or keep the hosted API for that call.

  5. Point clients at Ollama behind a feature flag

    Developers switch the client configuration to Ollama's OpenAI-compatible endpoint, keeping the hosted API as a fallback path controlled by a feature flag or configuration value. Each client is tested for request and response differences, such as streaming format, error shapes and token usage fields. The output is a tested client build where the provider can be changed without a redeploy. The phase closes when the fallback has been exercised in a non-production environment.

  6. Shift production traffic in stages

    Operators route a small, defined share of production requests to Ollama, watching error rates, latency, output quality samples and resource use on the host. They increase the share only after each stage meets thresholds agreed in advance, and they keep the hosted API ready to take all traffic back. The output is a dated log of each traffic change with the metrics that justified it. The phase closes when all in-scope traffic runs on Ollama and the fallback has been left in place for an agreed observation period.

  7. Hand over with a runbook

    The team writes a runbook covering installed versions, model tags, configuration keys, the proxy and access controls in front of Ollama, monitoring alerts, the rollback steps and the owners of each function. The operations team walks through the runbook and performs one rollback drill in a test environment. The output is an approved runbook and a named support contact for the platform. The phase closes when operations accepts ownership in writing.

How the migration changes by starting point and environment

Applications that only send chat completion requests are usually the simplest move, because the change is mostly the base URL, the model name and the handling of responses. The core question is whether the Ollama OpenAI-compatible endpoint returns what the application parses today. Confirm the current compatibility scope in the Ollama API documentation rather than assuming full parity with the hosted API.

  • Base URL and key handling: Point the client at the local server on port 11434 and confirm how the SDK sends or omits the API key, since the local API does not require authentication.
  • Model name mapping: Replace hosted model identifiers with the names of models you have pulled, and record the exact tag so later updates do not change behavior silently.
  • Streaming behavior: Test streamed responses end to end, including how the application detects the end of the stream and handles interruptions.
  • Parameter support: Compare each sampling and length parameter the application sends against what the endpoint honors, and remove or document any that are ignored.
  • Response parsing: Check fields such as finish reasons, token usage and error shapes, because the application may branch on them.

Before switching, run a fixed set of representative prompts through both endpoints and record where the parsed output differs in ways the application cannot tolerate.

Which parts teams keep in-house and which they outsource

A migration off a hosted model API touches product decisions, application code, infrastructure and evidence for data owners. The split below shows which work usually stays with your staff and which work partners often take, along with the skills each side needs before the first request moves.

Quality bar and acceptance decisions

Product owners decide what a good answer looks like for each feature, which failures are tolerable, and when a replacement open model is good enough to replace the hosted one. This judgment depends on knowledge of your users and business rules that no outside team holds. Check that the owner signs off on named acceptance criteria before any traffic moves, and that someone on the team can read model outputs critically rather than trusting a single benchmark score.

Application code changes

Your developers update the client code that calls the OpenAI SDK or REST API so it can point at a configurable base URL and model name. Ollama exposes an OpenAI-compatible endpoint on port 11434, but prompts, tool calls, streaming behavior and error handling still need testing in your own code paths. Application development skills in your language of choice are the main requirement, plus the ability to add feature flags for gradual switching.

Ollama FAQ

Data owner sign-off

Data owners decide which prompts, documents and customer records may be sent to a self-hosted model, and they approve the retention and logging rules for the new path. Your compliance and privacy staff own this decision, since moving to local inference changes where data is processed even though Ollama states that local runs do not expose prompts to it. Ask for a written data flow diagram and a named approver for each application before cutover.

Call inventory and dependency mapping

Partners often build the list of every service, script, prompt template, and third-party tool that calls the hosted API, including the models and parameters each one uses. Missing a single batch job or internal integration is a common cause of surprise after cutover. Ask for the inventory to be reviewed by the application owners, and confirm that keys issued to the hosted provider are tracked so they can be revoked later.

Hardware, server and model storage setup

A partner typically sizes the GPU or CPU hardware, installs the Ollama runtime, sets the model storage path with OLLAMA_MODELS, and tunes OLLAMA_NUM_PARALLEL and OLLAMA_MAX_QUEUE for expected load. This needs Linux administration, GPU driver operations and capacity planning. Your team should own the operating environment after handover and confirm who patches the host and drivers.

Evaluation harness and cutover runbook

Building a repeatable test set, scoring replacement models against it, and writing the runbook for gradual traffic shifts and rollback are specialist tasks that often sit with a partner, using evaluation design and test automation skills. Your team reviews results and keeps the test set current as prompts change. Ask whether the runbook covers a rollback path back to the hosted API and how each traffic percentage is approved.

Proxy and access configuration

Ollama's local API has no authentication, and the default bind is 127.0.0.1 on port 11434, so exposing it to other services requires a reverse proxy such as Nginx with access controls that your network team reviews. Networking, TLS and identity skills are needed here. Confirm who issues credentials for internal callers and who receives proxy logs.

What the migration leaves behind as recurring cost

This table lists the costs that continue after traffic moves from the hosted API to Ollama, with who pays for each and what drives it up. Read it alongside your current API invoice: the hosted bill is per-token usage, while the self-hosted side is mostly fixed infrastructure and staff time, plus any cloud plan you keep. Running models on your own hardware is listed as unlimited by Ollama, so the recurring question is capacity and people, not usage fees.

Cost componentWho is paid or who paysRecurring or one-timeWhat drives it
Hardware or cloud instanceHardware vendor or cloud providerRecurring (cloud) or one-time plus upkeep (owned)GPU or memory needed for the chosen models and peak concurrency
Power and coolingData center or your facility teamRecurringHours of inference load and idle draw of accelerators
Model file storageStorage vendor or your infrastructure teamRecurringNumber of model versions kept and the size of each model in ~/.ollama/models or OLLAMA_MODELS
Staff time for model updatesYour platform or ML operations teamRecurringHow often you re-test and roll new model versions through evaluation
Staff time for Ollama upgradesYour platform team or a support partnerRecurringRelease frequency, testing before rollout and how many environments you run
Monitoring and alertingYour observability team or tool vendorRecurringWhether queue depth, latency and loaded-model counts feed existing dashboards
Paid Ollama cloud plan (if kept)Ollama, per the pricing pageRecurring, monthly or yearlyPlan tier and whether any workload still calls cloud models; Enterprise pricing is custom, so request a written quote

What usually goes wrong in an OpenAI to Ollama migration and how to prevent it

Most failed migrations from a hosted model API to Ollama are not caused by the runtime itself. They come from untested model behavior, unexpected API differences, default settings nobody reviewed and switching that happens without a plan. Each card below pairs a risk with the control that prevents it.

Model passes casual tests but fails edge cases

A replacement open model can answer everyday prompts well and still fail on long documents, strict output formats, multilingual input or domain terms your users rely on. Build an evaluation set from real, anonymized production prompts, including the awkward ones, and score the candidate model against your current API outputs before any traffic moves. Record which failures are acceptable and which block the switch.

Unsupported or differently behaving API fields

The OpenAI-compatible endpoint covers many request fields, but tool calling, JSON modes, streaming details, token usage reporting and sampling parameters can behave differently or be ignored. Map every field your application sends, test each one against the local endpoint, and remove or adapt the ones that do not behave the same. Treat this compatibility table as part of the migration deliverable.

Ollama repository

Ollama port exposed beyond the intended network

Ollama binds to 127.0.0.1 on port 11434 by default and its local API requires no authentication. Teams that set OLLAMA_HOST to 0.0.0.0 so other services can reach it often publish an unauthenticated model endpoint on the internal network. Keep the default bind where possible, place any shared access behind a proxy with authentication, and check the listening address and firewall rules after every change.

Ollama FAQ

No fallback when the local server is down

If the application has only one endpoint, a restart, failed upgrade or full disk stops every feature that depends on the model. Decide in advance whether a failure should return a clear error, queue the request or route to a hosted provider during the transition. Put health checks on the Ollama endpoint, and keep the old API configuration available as a switch that can be flipped without a code deploy.

Memory exhaustion from concurrency defaults

Ollama allows one parallel request per model by default, and it can keep several models loaded at once. Traffic that was spread across a hosted API can queue behind a single local model, or load more models than the memory can hold. Set OLLAMA_NUM_PARALLEL, OLLAMA_MAX_LOADED_MODELS and OLLAMA_MAX_QUEUE deliberately against load tests on your hardware, and watch queue depth and memory during the staged rollout.

Default queued requests
512
Ollama FAQ

Unplanned model or version changes

Ollama releases frequently, and a model tag can point to a different build after an update, which changes output without any change in your code. Pin the exact model version and Ollama release in your configuration, record both with each evaluation run, and require the evaluation set to pass before either changes. Keep the previous model and runtime available so a rollback is a configuration change.

Ollama releases

What the client needs to provide before work starts

The scope of a migration from the OpenAI API to self-hosted Ollama cannot be fixed until the client provides four kinds of input: the current usage picture, approved test material, infrastructure access and named decision owners. Start with an export of hosted API usage: which models are called, which endpoints (chat completions, embeddings, tool calls or streaming), average and peak request volumes, and the list of applications and services that hold the API key. Without a call-site inventory, nobody can say which code paths must change, which prompts depend on specific model behavior, or which features, such as function calling or structured output, must be matched by the replacement model.

Next, supply a representative set of real prompts and the expected outputs, approved for use in testing by the data owner. The set should cover the common cases, the edge cases that have caused support tickets, and any prompts that contain regulated or personal data, with the handling rules for that data written down. Name who approves the test data and who signs off on quality, because the quality sign-off decides which replacement model and settings are acceptable. Also confirm where the hardware will run: an existing GPU server, a cloud account the client controls, or a data center, together with the network and DNS approvals needed to reach the Ollama endpoint from application subnets. Confirm the bind address and proxy policy with the security team before the first environment is built, since the local API has no authentication of its own.

Finally, decide two things before work starts: who owns the production switch, and who keeps the rollback path. The switch owner approves the traffic shift and its schedule. The rollback owner must be able to restore the hosted API configuration quickly, which means keeping the existing keys, client configuration and any feature flags in a state that can be reverted without a code release. Agree in writing who receives the quality report, who can halt the migration, and who is on call during each traffic step. If these owners are not named at kickoff, the quote will carry more uncertainty, and the test and cutover phases will stall waiting for decisions.

Common questions about migrating from the OpenAI API to Ollama

Does our application need code changes to move from the OpenAI API to Ollama?

Often very little, but it depends on which API features your code uses. Ollama exposes a REST API on port 11434 with OpenAI compatibility, so applications built on the OpenAI client libraries can usually be pointed at a different base URL and given a model name that exists on your server. The changes that tend to matter are model names, which will differ from the hosted catalog, and any dependence on features the compatibility layer does not mirror exactly, such as specific tool-calling behavior, structured output options, file uploads, or hosted-only models. Map every endpoint and parameter your code calls, then test each one against your Ollama server before changing production configuration.

What drives the effort of an OpenAI to Ollama migration?

The main drivers are the number of applications and integrations that call the API, how many distinct endpoints and parameters they use, and how much prompt behavior depends on a specific hosted model. Each client that needs a different model, prompt rewrite or error-handling change adds work. Evaluation effort grows with the number of use cases you must prove still work. Hardware sizing, model storage and the proxy in front of the server also affect scope, because they determine which models you can run at acceptable speed. Ask any partner to break the estimate down by application, endpoint and evaluation set so you can see what each part costs.

Can our own engineering team migrate to Ollama without outside help?

Many teams can, particularly when they have a small number of applications, engineers who already run containers or Linux servers, and time to run structured tests. The skills that usually take longest are sizing GPU and memory for the models you choose, building an evaluation set that reflects real traffic, and putting authentication in front of the local API, which has none by default. Ask yourself whether your team can own those three areas after go-live, including model updates and patching. If not, a fixed-scope engagement covering only the parts you cannot staff is a common middle path.

How do we check that output quality holds after switching models?

Build a fixed evaluation set from logged production prompts, with representative and edge-case inputs, and score the current hosted model and each candidate open model against the same set. Define acceptance criteria per use case before testing, such as factual accuracy, format compliance, refusal behavior and tool-call correctness, and combine automated checks with human review of a sample. Repeat the evaluation whenever you change a model tag, quantization or Ollama version, because outputs can shift between them. Ask for the scoring method and the pass criteria in writing, not just a statement that quality was reviewed.

What does the client need to provide for a migration engagement?

The client typically provides access to the applications and their repositories, a representative sample of prompts and responses, the hardware or cloud accounts where Ollama will run, and named owners for security review and change approval. You will also need to decide where models are stored, which the Ollama FAQ describes as configurable through the OLLAMA_MODELS variable, and who receives the logs. Confirm early whether production data may be used in test sets and whether the environment is air-gapped, since both change the work. Missing access or unclear data rules are among the most common causes of schedule slippage.

How should a migration quote be structured?

A useful quote separates one-time work from recurring costs and lists each deliverable against a written scope. Ask for line items covering discovery and endpoint mapping, the evaluation set and scoring method, server and model setup, client configuration changes, the authentication and proxy layer, cutover and rollback steps, and handover documentation. Each item should name what is excluded, the assumptions about hardware and data access, and what triggers a change request. Recurring items such as model updates, patching and support should appear separately. Ask whether the price is fixed for the agreed scope and how additional applications would be priced.

What happens to the OpenAI API contract during the switch?

The hosted API contract, including your API keys, usage terms and any data processing agreement, continues to govern traffic that still reaches OpenAI, so keep it active until the switch is complete and verified. The safer pattern is to route traffic through a gateway or configuration flag that can send a percentage of requests to Ollama, compare results, and fall back to the hosted API if quality or latency drops. Once no application depends on the hosted endpoint, review the contract, revoke unused keys and confirm with your legal and procurement teams what notice or termination steps apply.

How DeployOpen scopes, delivers and hands over an Ollama migration

DeployOpen plans and implements migrations from a hosted model API to self-hosted Ollama inside your own infrastructure. The work is agreed in a written, fixed-scope plan, tested against your applications, and handed over with documentation your team can run.

How we scope

  • Inventory every application and script that calls the hosted API, including model names, parameters and streaming use.
  • Agree in writing which endpoints move to the OpenAI-compatible interface on Ollama and which stay on the hosted API.
  • Define the quality test set, acceptance criteria and the traffic-switch steps before any production change is made.

How we build

  • Point client applications at the Ollama endpoint in a staging environment and fix compatibility gaps in request handling.
  • Run candidate open models against your test set and record output quality, latency and failure cases side by side with the current API.
  • Set up gradual traffic switching with a documented rollback path, so each application can return to the hosted API if needed.

How we hand over

  • Deliver written documentation of the endpoint configuration, model choices, test results and the switching runbook.
  • Walk your platform and application teams through model storage locations, concurrency settings and how to add or replace a model.
  • Confirm with your security team how the local API, which has no built-in authentication, is reached and who can change its configuration.

How we support

  • Agree the post-go-live support period in the written scope, with any further work quoted separately.
  • Offer ongoing support, upgrades and continuous testing as a retainer, including retesting when Ollama or a model version changes.
  • Ask your DeployOpen contact to confirm which support channel and response expectations apply before the engagement starts.

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.