PREDICTIVE TREND INSIGHT
How to connect local small language models to store APIs Illustration

How to connect local small language models to store APIs

Direct Summary:

Local small language models (via Ollama) support the same tool-calling pattern as cloud APIs: the model doesn't call your store's API directly — it returns a structured request naming a function and its arguments, and your code decides whether to actually execute the call against Shopify, WooCommerce, or another store platform. Models like Llama 3.1 and Qwen2.5 support this via Ollama's tool-calling interface, which uses the same JSON Schema format as the OpenAI API, so an existing tool definition typically works without rewriting.

"Good tools make the craft invisible."

— Unknown

Key Insights

  • The model never touches your API credentials directly: it only returns a structured tool-call request (function name + arguments) — your own code holds the store API key and decides whether to actually execute the call.
  • Not every local model supports tool calling: Ollama's supported-models list (Llama 3.1, Mistral Nemo, Qwen2.5, and others tagged "Tools") is the ground truth — check it before assuming an arbitrary local model can do this.
  • Local means the reasoning happens on your hardware, not that store data stays "more private" by magic: the actual privacy benefit is that the customer query/context never leaves your machine to reach a third-party inference API — the store API call itself still goes over the network to the store platform regardless.

Tool calling with a local model works identically in structure to tool calling with a cloud API — the difference is only where the reasoning step happens. Your Python code defines a function (e.g., "look up order status"), describes it in a JSON schema the model can read, and the local model decides when to invoke it and with what arguments. Your code, not the model, actually executes the API call to the store platform.

Wiring a local model to a store API

1. Confirm your chosen model supports tool calling. Check Ollama's model library for the "Tools" tag — Llama 3.1, Mistral Nemo, and Qwen2.5 are commonly cited as supporting this; not every local model does.

2. Define the store lookup as a tool with a JSON schema. Describe the function's name, purpose, and parameters (e.g., order ID) in the same schema format the OpenAI API uses — Ollama's tool-calling interface follows this convention.

3. Execute the actual API call in your own code, not the model. When the model returns a tool-call request, your code validates the arguments and makes the real HTTP call to the store's API (Shopify Admin API, WooCommerce REST API) — the model never holds your store credentials.

local_store_tool.py
# pip install ollama
import ollama

def get_order_status(order_id: str) -> dict:
    # Your code makes the real call to the store API here --
    # the model never sees or holds the API key
    return {"order_id": order_id, "status": "shipped"}

response = ollama.chat(
    model="llama3.1",
    messages=[{"role": "user", "content": "What's the status of order #4471?"}],
    tools=[{
        "type": "function",
        "function": {
            "name": "get_order_status",
            "description": "Look up the shipping status of a store order",
            "parameters": {
                "type": "object",
                "properties": {"order_id": {"type": "string"}},
                "required": ["order_id"]
            }
        }
    }]
)
Aspect Cloud API Tool Calling Local Model (Ollama) Tool Calling
Where reasoning happens Provider's servers Your own hardware
Schema format OpenAI-style JSON Schema Same JSON Schema format — compatible tool definitions
Who holds the store API key Your code (never the model) Your code (never the model)

The main practical reason to reach for a local model here is keeping the customer's query text off a third-party inference API — the store API call itself still travels over the network either way, since that's the store platform's own endpoint. Choose a local model specifically for that reasoning-privacy benefit, not under the assumption that "local" makes the entire pipeline more private end-to-end.

Practical Challenge

Install Ollama with a tool-calling-capable model (e.g., Llama 3.1), define a mock get_order_status tool like the one above, and confirm the model correctly extracts the order ID from a natural-language question and returns a valid tool-call request.

Concept Check

When a local Ollama model uses tool calling to look up a store order, who actually executes the API call to the store platform?
Correct! Tool calling means the model proposes a function call; your code decides whether to execute it and holds the actual API credentials — this is true for local models exactly as it is for cloud APIs.
Incorrect. Try again! The model never holds API credentials or makes the call directly — it only returns a structured tool-call request that your own code executes.

Sources & Further Reading

Previous Guide Dashboard Next Guide