continue icon indicating copy to clipboard operation
continue copied to clipboard

openai configuration to AnythingLLM API doesn't show response tokens

Open jasongreb opened this issue 5 months ago • 2 comments

Before submitting your bug report

Relevant environment info

- OS: Windows 11
- Continue version: 1.2.22
- IDE version: 1.124.2
- Model: OpenAI (AnythingLLM API)
- config:
  
  - name: AnythingLLM NPU Phi3.5 3.8B 4K
    provider: openai
    apiKey: APIKEY
    model: vscode
    env:
      useLegacyCompletionsEndpoint: false
    apiBase: http://localhost:3001/api/v1/openai
    roles:
      - chat
      - edit
      - apply
    defaultCompletionOptions:
      contextLength: 4096
      temperature: 0.2
      maxTokens: 2048

Description

When I use the OpenAI provider along with the AnythingLLM API, responses are not shown within the chat window. Responses are being generated and chunked data is being returned as viewed within a packet capture. Other models via Ollama work fine and provide responses. A quick comparison of network traffic shows that the response data from Ollama matches that of the AnythingLLM API. Example response from the API:

POST /api/v1/openai/chat/completions HTTP/1.1
accept: application/json
accept-encoding: gzip, deflate, br
authorization: Bearer APIKEY
content-length: 1998
content-type: application/json
user-agent: OpenAI/JS 5.23.2
x-stainless-arch: arm64
x-stainless-lang: js
x-stainless-os: Windows
x-stainless-package-version: 5.23.2
x-stainless-retry-count: 0
x-stainless-runtime: node
x-stainless-runtime-version: v24.15.0
Host: 127.0.0.1:3001
Connection: close

{"messages":[{"role":"system","content":"<important_rules>\n  You are in chat mode.\n\n  If the user asks to make changes to files offer that they can use the Apply Button on the code block, or switch to Agent Mode to make the suggested updates automatically.\n  If needed concisely explain to the user they can switch to agent mode using the Mode Selector dropdown and provide no other details.\n\n  Always include the language and file name in the info string when you write code blocks.\n  If you are editing \"src/main.py\" for example, your code block should start with '```python src/main.py'\n\n  When addressing code modification requests, present a concise code snippet that\n  emphasizes only the necessary changes and uses abbreviated placeholders for\n  unmodified sections. For example:\n\n  ```language /path/to/file\n  // ... existing code ...\n\n  {{ modified code here }}\n\n  // ... existing code ...\n\n  {{ another modification }}\n\n  // ... rest of code ...\n  ```\n\n  In existing files, you should always restate the function or class that the snippet belongs to:\n\n  ```language /path/to/file\n  // ... existing code ...\n\n  function exampleFunction() {\n    // ... existing code ...\n\n    {{ modified code here }}\n\n    // ... rest of function ...\n  }\n\n  // ... rest of code ...\n  ```\n\n  Since users have access to their complete file, they prefer reading only the\n  relevant modifications. It's perfectly acceptable to omit unmodified portions\n  at the beginning, middle, or end of files using these \"lazy\" comments. Only\n  provide the complete file when explicitly requested. Include a concise explanation\n  of changes unless the user specifically asks for code only.\n\n</important_rules>"},{"role":"user","content":"Hey there, just testing. Are you able to help me code?"},{"role":"user","content":"Sorry, I don't seem to be getting any output from you."}],"model":"vscode","max_tokens":4096,"stream":true,"stream_options":{"include_usage":true}}
HTTP/1.1 200 OK
X-Powered-By: Express
Vary: Origin
Cache-Control: no-cache
Content-Type: text/event-stream
Access-Control-Allow-Origin: *
Connection: keep-alive
Date: Sun, 14 Jun 2026 19:24:27 GMT
Transfer-Encoding: chunked

data: {"id":"79755aff-21d8-4dca-8cce-462b39304594","object":"chat.completion","created":1781465068,"model":"vscode","choices":[{"index":0,"delta":{"role":"assistant","content":"No"},"logprobs":null,"finish_reason":null}],"usage":{}}

data: {"id":"79755aff-21d8-4dca-8cce-462b39304594","object":"chat.completion","created":1781465069,"model":"vscode","choices":[{"index":0,"delta":{"role":"assistant","content":" worries"},"logprobs":null,"finish_reason":null}],"usage":{}}

The output console shows 0 tokens returned and the logs show no errors related to responses.

To reproduce

  1. Install AnythingLLM and set up a Workspace connected to an LLM.
  2. Enable the AnythingLLM API and create an API key.
  3. Configure a new model on Continue to point to the AnythingLLM API along with the API key.
  4. Create a new chat and send the message.
  5. Review the console output and check the response tokens to confirm 0.

Log output


jasongreb avatar Jun 14 '26 21:06 jasongreb

Since you confirmed via packet capture that response chunks ARE being returned with correct data, the issue is in how Continue's OpenAI provider parses the streaming response from AnythingLLM — not a server-side problem.

Most likely cause: SSE content-type or chunk format mismatch

AnythingLLM's OpenAI-compatible endpoint may return chunks in a slightly different format than what the OpenAI JS SDK expects. Common differences:

  1. Missing content-type: text/event-stream header — if AnythingLLM returns application/json instead, the OpenAI SDK won't parse the response as SSE and may silently discard the body.

  2. Chunk delimiter format — the OpenAI streaming spec requires data: {...}\n\n (double newline). Some local backends use data:{...}\n (single newline, no space after data:). The OpenAI SDK is strict about this format.

  3. [DONE] sentinel — the stream must end with data: [DONE]\n\n. If AnythingLLM omits this or sends it differently, the SDK may wait indefinitely for more data and never flush the accumulated content.

Debugging:

Compare the raw SSE output between Ollama (working) and AnythingLLM (broken):

# AnythingLLM raw SSE
curl http://localhost:3001/api/v1/openai/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_KEY" \
  -d '{"model":"vscode","messages":[{"role":"user","content":"hi"}],"stream":true}' \
  --no-buffer 2>&1 | head -20

# Compare with Ollama raw SSE
curl http://localhost:11434/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model":"YOUR_MODEL","messages":[{"role":"user","content":"hi"}],"stream":true}' \
  --no-buffer 2>&1 | head -20

Check: are the response headers identical? Are the data: line formats the same? Does both end with data: [DONE]?

If the format differs, an OpenAI-compatible API gateway between AnythingLLM and Continue can normalize the SSE output to strict OpenAI format, which avoids SDK parsing issues.

OpenAI-compatible endpoint configuration checklist: https://futurmix.ai/docs/integration-guide?utm_source=github&utm_medium=issue_reply&utm_campaign=continue

Disclosure: I work on FuturMix, an OpenAI-compatible API gateway, and put together these docs while debugging similar SSE compatibility issues. Sharing in case it helps.

FuturMix avatar Jun 15 '26 03:06 FuturMix

The Content-Type is being returned as text/event-stream, and there are two new line characters after each data: element (confirmed at byte level). It does not return the data: [DONE], but a finish_reason is provided.

As for comparing the two, Ollama is using a different backend so the returned format is different. The content type is application/x-ndjson.

jasongreb avatar Jun 20 '26 12:06 jasongreb