Applications can reuse the models connected to Open WebUI without opening its chat interface. A chat request through the Open WebUI API sends a conversation to an allowed model and returns its assistant response.

The chat completion route is POST /api/chat/completions, and it accepts an OpenAI-style messages array plus a model ID from Open WebUI. A user API key authenticates the request with the account's existing model access and permissions.

Non-streaming requests return one JSON response after generation finishes. Prompts still reach the selected model provider, whose privacy rules and usage charges apply even when Open WebUI is self-hosted.

Steps to send a chat request through the Open WebUI API:

The starting point is Bash with curl 7.76 or newer and jq installed, plus an API key from a standard account permitted to use a connected model. If API-key endpoint restrictions are enabled, the administrator's allowed paths must include /api/models and /api/chat/completions. Key creation and permission changes belong to How to enable API keys in Open WebUI.

An API key grants access as its owner. The key must stay out of repositories, shared logs, tickets, and screenshots. Request and response files can contain private conversations; the working directory must be private, and the prompt must be suitable for the chosen provider.

  1. Disable Bash tracing before handling the API key.
    $ set +x
  2. Restrict newly created request and response files to your account.
    $ umask 077
  3. Set the Open WebUI base URL for the terminal session.
    $ export OPEN_WEBUI_URL="https://openwebui.example.com"
  4. Read the API key into a shell variable without echoing it.
    $ IFS= read -r -s -p 'Open WebUI API key: ' OPEN_WEBUI_API_KEY

    The value is entered at the prompt rather than in a shell command. The variable stays in the current shell instead of being exported to child processes.

  5. List the model IDs visible to the API key.
    $ printf 'Authorization: Bearer %s\n' "$OPEN_WEBUI_API_KEY" |
      curl -q --fail-with-body --silent --show-error \
        --header @- "$OPEN_WEBUI_URL/api/models" |
      jq -r '.data[].id'
    company-chat

    The header reaches curl through standard input so the expanded key is absent from curl's process arguments. An empty list means no model is available to this account; authentication, permissions, endpoint restrictions, and proxy forwarding of the Authorization header can cause 401 or 403 responses.

  6. Create the chat request body with an exact model ID from the list.
    $ cat > openwebui-chat.json <<'JSON'
    {
      "model": "company-chat",
      "messages": [
        {"role": "user", "content": "Name the capital of France in one short sentence."}
      ],
      "stream": false
    }
    JSON
  7. Send the chat request into a saved response file.
    $ printf 'Authorization: Bearer %s\n' "$OPEN_WEBUI_API_KEY" |
      curl -q --fail-with-body --silent --show-error \
        --header @- "$OPEN_WEBUI_URL/api/chat/completions" \
        --header 'Content-Type: application/json' \
        --data @openwebui-chat.json \
        --output openwebui-response.json

    Generation can take time. A successful HTTP status alone does not prove that assistant text was returned. An error body remains in openwebui-response.json if curl reports an HTTP failure.

  8. Confirm that the saved response contains nonempty assistant text.
    $ jq -e '.choices[0].message | select(.role == "assistant") | .content | strings | select(length > 0)' \
      openwebui-response.json
    "The capital of France is Paris."

    The command prints the returned text and exits unsuccessfully if it is missing or empty. Invalid JSON can indicate an HTML proxy error or a streaming response; a model's saved Stream Chat Response setting can override stream: false.

  9. Clear the API key from the shell variable.
    $ unset OPEN_WEBUI_API_KEY
  10. Remove the temporary request body after confirming the response.
    $ rm openwebui-chat.json

    The saved openwebui-response.json remains available for inspection or use by another local program.

Share this guide