Skip to content

Instantly share code, notes, and snippets.

@dobriak
Created March 19, 2026 06:13
Show Gist options
  • Select an option

  • Save dobriak/cd83798d40f5a64bd507270126cadbb2 to your computer and use it in GitHub Desktop.

Select an option

Save dobriak/cd83798d40f5a64bd507270126cadbb2 to your computer and use it in GitHub Desktop.
Opencode for some reason does not know how to parse model data if used with local llama.cpp server. This jq filter parses the output of Open AI `v1/models` in a format that can be pasted into opencode config providers/llama.cpp models setting
#!/usr/bin/env bash
LLAMA_CPP_BASE_URL=https://llamacpp.your-url.com
curl -s ${LLAMA_CPP_BASE_URL}/v1/models | jq '[.data[] |
.status.args as $args |
{
(.id): {
name: .id,
limit: (
($args | index("--ctx-size")) as $idx |
if $idx then {context: ($args[$idx + 1] | tonumber), output: ($args[$idx + 1] | tonumber)} else empty end
)
}
}
] | add'
@dobriak

dobriak commented Mar 19, 2026

Copy link
Copy Markdown
Author

The output will look like this:

{
  "GLM-4.7-Flash": {
    "name": "GLM-4.7-Flash",
    "limit": {
      "context": 184320,
      "output": 184320
    }
  },
  "JoyAI-LLM-Flash": {
    "name": "JoyAI-LLM-Flash",
    "limit": {
      "context": 128000,
      "output": 128000
    }
  },
  "LFM2-24B-A2B": {
    "name": "LFM2-24B-A2B",
    "limit": {
      "context": 32768,
      "output": 32768
    }
  },
....

So in your ~/.config/opencode/opencode.json you can have this snippet:

...
 "provider": {
    "llama.cpp": {
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://llamacpp.your-url-here.com/v1",
        "apiKey": "none",
        "api": "openai-completions"
      },
      "models": {
        "GLM-4.7-Flash": {
          "name": "GLM-4.7-Flash",
          "limit": {
            "context": 184320,
            "output": 184320
          }
        },
        "JoyAI-LLM-Flash": {
          "name": "JoyAI-LLM-Flash",
          "limit": {
            "context": 128000,
            "output": 128000
          }
        },
        "LFM2-24B-A2B": {
          "name": "LFM2-24B-A2B",
          "limit": {
            "context": 32768,
            "output": 32768
          }
        },
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment