CLIO icon indicating copy to clipboard operation
CLIO copied to clipboard

[Feature]: Add Synap provider (OpenAI-compatible, open-weight models)

Open jimmyplup opened this issue 3 weeks ago • 5 comments

Pre-submission Checklist

  • [x] I have searched existing issues and discussions
  • [x] I have read the documentation
  • [x] This is a feature request, not a bug report

Problem Statement

CLIO has no built-in provider for Synap. Synap is an OpenAI-compatible inference endpoint for open-weight models, served on dedicated GPUs we operate ourselves, with one API key for the whole catalogue and no prompt retention.

Today a CLIO user has to wire it up as a custom endpoint by hand: type the base URL, work out the model ids, and set the context limits themselves. A built-in entry gives a fixed default URL, a documented env var and model discovery.

Disclosure: I work on Synap (Linkrra).

Proposed Solution

Add synap as an OpenAI-compatible provider, the same way as cheaperinference (#39) and standardcompute (#42) — those are already in tree in lib/CLIO/Providers.pm, lib/CLIO/Core/model-data/provider-defaults.json and lib/CLIO/Core/model-data/provider-mapping.json, each with a unit test, so this is the same registry entry one more time.

  • api_base: https://pool.linkrra.com/v1/chat/completions
  • Auth: API key, Authorization: Bearer <key>; env SYNAP_API_KEY
  • Model list: public GET https://pool.linkrra.com/v1/models (no key needed, returns 14 entries today)
  • Tools and streaming: yes, both declared per model in the catalogue feed
  • Default model: synap-v1, which is routed — each request goes to the cheapest model in our catalogue that can do the job (tools / code / reasoning), billed at the price of whichever model actually ran
  • Pinned ids for a coding agent: qwen3-coder-30b, gpt-oss-20b, qwen/qwen3-30b-a3b-instruct-2507, deepseek/deepseek-v4-pro, z-ai/glm-5.3-flash
  • Context: 98,304 tokens on qwen3-coder-30b and qwen/qwen3-30b-a3b-instruct-2507, 131,072 on meta/muse-glimmer-30b, 65,536 on gpt-oss-20b

Prices come from the live catalogue feed, per million tokens, in / out: gpt-oss-20b $0.017 / $0.085 · qwen3-coder-30b $0.0675 / $0.27 · qwen/qwen3-30b-a3b-instruct-2507 $0.0813 / $0.2438 · gemma-4-26b-a4b-it $0.04 / $0.21. That matters for a terminal agent that burns context all day.

Docs: https://synap.linkrra.com/docs.html · machine-readable catalogue in OpenRouter schema 2.4: https://pool.linkrra.com/v1/models?format=openrouter

I'm happy to open the PR myself against the cheaperinference pattern if you'd rather review a diff than a request.

Which area would this affect?

API / Provider Integration

Alternatives Considered

A custom OpenAI-compatible endpoint already works, but every user has to enter the URL and the model list by hand, and nothing discovers new models when we add them. Leaving it out also means CLIO has built-in entries for two gateways of the same shape and not this one.

Additional Context

The provider is live now: GET https://pool.linkrra.com/v1/models answers 200, and POST /v1/chat/completions without a key answers 402 rather than 401, because the same endpoint also accepts per-call payment — irrelevant to this issue, and it does not change the API-key path, but worth knowing if a test asserts on 401.

jimmyplup avatar Nov 10 '26 16:11 jimmyplup

Automated Triage Summary

Field Value
Classification enhancement
Priority low
Completeness 90%

Analysis: Legitimate, well-specified feature request from the vendor (disclosed). The pattern is exactly as described: cheaperinference, cheapaimodel, and standardcompute are in-tree OpenAI-compatible route-based providers, and I confirmed the live https://pool.linkrra.com/v1/models feed returns 200 with 14 entries and the reporter's context/pricing figures are accurate. Three gaps the request does not cover. (1) SYNAP_API_KEY is not a supported mechanism - APIManager::_get_api_key only reads CLIO_API_KEY, and no per-provider env var path exists; docs should follow the Standard Compute precedent and document CLIO_API_KEY. (2) The public model feed is not in a shape CLIO's parsers read: context is nested at input_modalities[0].supported_inputs.max_context_length.value and output at output_modalities[0].max_length.value, but _fetch_openai_compatible_capabilities reads only context_length/context_window/max_tokens/top_provider.*, and Models.pm reads architecture.input_modalities rather than top-level input_modalities; Synap's supported_parameters is a hash where MCM's tool fallback requires an array. Chat completions will work, but /api models would show '-' for context/output and per-model tool detection is lost unless the feed is normalized or a provider-specific parse path is added. (3) synap-v1, the proposed default, has no capability metadata in the feed at all (pure router id resolving to gpt-oss-20b), so provider-defaults.json must declare explicit max_context_tokens/max_output_tokens - and choosing that value is a real design decision since the router can pick a 131,072-context model. Implementation checklist: add the registry entry with route_timeout => 1 and url_detection_patterns => [qr{pool.linkrra.com}i]; add provider-defaults.json entry with reasoning_schema {mode: disabled} (required by test_api_config_reasoning.pl) and explicit context/output; add provider-mapping.json entry with model_id_format 'provider/model' (required by test_mcm_openrouter_fix.pl Test 13); update the 22->23 count in README.md (2 places), AGENTS.md, docs/ARCHITECTURE.md (2 places), docs/DEVELOPER_DOCUMENTATION_GUIDE.md, docs/FEATURES.md, docs/USER_GUIDE.md; add the PROVIDERS.md table row and section; extend test_providers_flags.pl @CLOUD_NAMES and the default_context_window chain, test_provider_timeout_tiers.pl @route_providers, test_provider_from_url.pl, and test_openai_compatible_mcm_url.pl; add tests/unit/test_synap_provider.pl modeled on test_standardcompute_provider.pl. Note for the test author: POST without a key returns 402 (billing_error), not 401 (auth_failed), so do not assert on 401. Separately, the README provider table is already stale - it lists SAM (not in the registry) and omits cheaperinference, cheapaimodel, and standardcompute, giving 20 rows for 22 providers; the doc-count test only checks numeric claims so this passes today. Worth fixing in the same PR. The reporter offered to open the PR against the cheaperinference pattern, which is the right approach.

Root Cause Analysis

Confidence: high

Relevant files:

  • lib/CLIO/Providers.pm
  • lib/CLIO/Core/model-data/provider-defaults.json
  • lib/CLIO/Core/model-data/provider-mapping.json
  • lib/CLIO/Core/ModelCapabilitiesManager.pm
  • lib/CLIO/UI/Commands/API/Models.pm
  • lib/CLIO/Core/APIManager.pm
  • docs/PROVIDERS.md
  • README.md
  • AGENTS.md
  • docs/ARCHITECTURE.md
  • docs/FEATURES.md
  • docs/USER_GUIDE.md
  • docs/DEVELOPER_DOCUMENTATION_GUIDE.md
  • tests/unit/test_provider_doc_count.pl
  • tests/unit/test_providers_flags.pl
  • tests/unit/test_provider_timeout_tiers.pl
  • tests/unit/test_provider_from_url.pl
  • tests/unit/test_openai_compatible_mcm_url.pl

Relevant functions:

  • CLIO::Providers::get_provider
  • CLIO::Providers::build_endpoint_config
  • CLIO::Providers::provider_from_url
  • CLIO::Core::ModelCapabilitiesManager::_fetch_openai_compatible_capabilities
  • CLIO::Core::ModelCapabilitiesManager::_find_model_in_list
  • CLIO::UI::Commands::API::Models::_fetch_provider_models
  • CLIO::Core::APIManager::_get_api_key
  • CLIO::Core::APIManager::_parse_model_provider
  • CLIO::Core::ModelDataLoader::_normalize_model_id

This is a registry-addition request, not a bug. The cheaperinference/cheapaimodel/standardcompute entries in lib/CLIO/Providers.pm (lines ~363-420) are the exact template: api_base with full /v1/chat/completions path, requires_auth => 'apikey', supports_tools/supports_streaming, route_timeout => 1 (Synap's synap-v1 is a router, so this applies), url_detection_patterns => [qr{pool.linkrra.com}i], and an endpoint block with path_suffix => '' and temperature_range [0.0, 2.0]. Three things the request does not account for. (1) SYNAP_API_KEY is not a supported mechanism: APIManager::_get_api_key (line 840) only reads CLIO_API_KEY, and no per-provider env var path exists; docs should say CLIO_API_KEY, matching the Standard Compute section at docs/PROVIDERS.md:454. (2) The live /v1/models feed nests context at input_modalities[0].supported_inputs.max_context_length.value and output at output_modalities[0].max_length.value, but _fetch_openai_compatible_capabilities (line 2852) only reads context_length/context_window/max_tokens/max_context_tokens/meta.n_ctx/top_provider.*, and Models.pm reads architecture.input_modalities rather than top-level input_modalities. Synap's supported_parameters is a hash, while MCM's tool-detection fallback (line ~3040) requires an ARRAY. So chat completions work but /api models would render '-' for context/output and lose per-model tool detection. (3) synap-v1, the proposed default, has no context_length, pricing, or modalities in the feed at all (it is a pure router id resolving to gpt-oss-20b), so provider-defaults.json must carry explicit max_context_tokens/max_output_tokens. model_id_format should be 'provider/model' (as standardcompute uses) because Synap mixes bare ids (synap-v1, qwen3-coder-30b, gpt-oss-20b) with org/model ids (qwen/qwen3-30b-a3b-instruct-2507, deepseek/deepseek-v4-pro); _normalize_model_id's s{^[^/]+/}{} is a no-op on bare ids, so one format covers both. No keep_model_prefix is needed: _parse_model_provider correctly splits synap/deepseek/deepseek-v4-pro into ('synap','deepseek/deepseek-v4-pro').

Affected Areas

  • Provider registry (lib/CLIO/Providers.pm)
  • Model capability data (provider-defaults.json, provider-mapping.json)
  • Model discovery and /api models display (Models.pm, ModelCapabilitiesManager.pm)
  • Documentation provider counts in 7 files (guarded by test_provider_doc_count.pl)
  • Provider flag/timeout/URL-detection unit tests
  • Pre-existing README provider table drift (lists SAM, omits 3 registered providers)

This is an automated analysis. A maintainer will review shortly.

CLIO-Bot avatar Nov 10 '26 16:11 CLIO-Bot

Thanks — the triage is accurate, and I verified all three gaps against the live feed before answering. Two of them are worse than stated, so I would rather you have the exact picture than a vendor's reassurance.

1. API key env var. Agreed, SYNAP_API_KEY is not a thing here. The docs should say CLIO_API_KEY, matching the Standard Compute section.

2. The model feed shape — confirmed, and broader than the issue implies. I read https://synap402.com/v1/models and https://pool.linkrra.com/v1/models just now, 14 entries:

  • 0 of 14 entries carry a top-level context_length, context_window, max_tokens or top_provider.*. Context lives only at input_modalities[0].supported_inputs.max_context_length.value and output at output_modalities[0].max_length.value, exactly as you found.
  • 8 of 14 carry no capability metadata at all, nested or otherwise: the four router/alias ids (synap-v1, synap-v1-pro, team-planner, team-worker) and the four upstream-served ids (qwen/qwen3.5-122b-a10b, z-ai/glm-5.3-flash, deepseek/deepseek-v4-pro, deepseek/deepseek-v4-flash). Only the six models on our own GPUs have the nested values.
  • supported_parameters is an object keyed by parameter name, not an array, so a fallback that expects an array will not detect tools/tool_choice even though all six self-served models support both.
  • There is no architecture object anywhere in the feed.
  • ?format=openrouter does not help: it returns the same schema_version: 2.4 nested shape and only 6 of the 14 ids. Please don't wire anything to it expecting the OpenRouter catalog schema.

That is our bug, not CLIO's, and it affects every integration that auto-detects capability rather than hard-coding it. I have filed it on our side to emit the conventional top-level fields — context_length, top_provider.max_completion_tokens, an architecture block, and supported_parameters as a flat array of strings — alongside the existing nested 2.4 fields, so nothing that reads 2.4 today breaks. Until that ships, provider-defaults.json carrying explicit values is the right call rather than parsing our feed.

3. synap-v1 as the default. You are right that it is a pure router id with no metadata, and right that picking its context number is a design decision rather than a lookup. Suggest making gpt-oss-20b the documented default instead: it is a fixed model, 65,536 context, and it is what synap-v1 resolves to today, so the defaults file states a fact rather than a guess.

One correction for whoever writes the tests: confirmed live just now — a POST /v1/chat/completions with no key returns 402 with an x402 payment-required body, not 401. Asserting 401 will fail.

Happy for the PR to follow the cheaperinference template as you describe, including the stale README provider table in the same change. If you would rather land the registry entry only and keep docs separate, say so and I will split it.

jimmyplup avatar Nov 10 '26 18:11 jimmyplup

Follow-up Triage

Re-analysis triggered by new activity on this issue. Updated triage based on the latest comments.

Field Value
Classification enhancement
Priority medium
Completeness 92%

Analysis: Thanks - the live census (14 entries, 8 with no metadata, no architecture object, and ?format=openrouter returning the same nested 2.4 shape for only 6 ids) is more useful than my first pass, and it made me re-check two things I got wrong.

Correction 1: provider-defaults.json alone will not fix trimming, so it should not ship as the sole mitigation. I traced the path. _fetch_openai_compatible_capabilities (ModelCapabilitiesManager.pm) reads context from context_length / context_window / max_tokens / max_context_tokens / meta.n_ctx / meta.n_ctx_train / top_provider.* and nothing else - no input_modalities - so all 14 of your ids come back context_window => undef, not 8. The only two functions that consult $provider_def->{max_context_tokens} are the Anthropic parsers (_parse_anthropic_per_model_response, _build_anthropic_caps_from_list_entry); the OpenAI-compatible path never reads it, so neither a registry field nor a defaults-file value reaches the caps hash.

That matters downstream. APIManager::get_model_capabilities builds its cache entry with max_context_window_tokens => $caps->{context_window} (undef) and returns it at the MCM branch because the hashref itself is truthy, so the default_context_window($mcm_provider) fallback ~15 lines below is unreachable. TokenEstimator::compute_prompt_budget then sees no context and falls back to DEFAULT_CONTEXT_WINDOW (128000). Run against the exact hash shape this code produces, gpt-oss-20b gets a 97,024-token prompt budget against a real 65,536 - 31,488 over. MessageValidator's $max_prompt does fall back to default_context_window, but it is only used in a log_debug line; the trim decision uses compute_prompt_budget() and $effective_limit instead, so the provider default gates nothing.

So the symptom is not '-' in /api models (that part I had right). It is a budget that overshoots by roughly 31K-65K tokens on the first request, a 400 context_length_exceeded, and a reactive-trim retry - one wasted round trip and two rounds of trimming per long conversation, on all 14 ids. This is pre-existing CLIO behaviour for any OpenAI-compatible feed without top-level context fields, not Synap-specific.

The fix that actually makes the provider work is small and follows the Anthropic precedent: in _fetch_openai_compatible_capabilities, after extraction, add $context_window //= $provider_def->{max_context_tokens} and $output_tokens //= $provider_def->{max_output_tokens}. With that, gpt-oss-20b computes to 37,684 instead of 97,024. Belt-and-braces would be relaxing the APIManager early return so an all-undef token hash falls through to the provider default, but the fetcher change is the one that matters.

One caution for your feed fix: do not map output_modalities[0].max_length.value into max_completion_tokens. max_length is total sequence length, so it equals the context window, and compute_prompt_budget reserves output before computing the prompt allowance. Measured: ctx=out=65536 -> 1,000-token budget; 98304 -> 1,000; 131072 -> 1,000. It collapses to the floor. Emit a real completion cap (16,384 is sane) or omit the field.

Correction 2: my model_id_format: 'provider/model' note was wrong on both value and justification. Test 13 in test_mcm_openrouter_fix.pl only asserts that every registry provider has an entry in provider-mapping.json; no test anywhere references model_id_format values. And 'provider/model' flows through _normalize_model_id's s{^[^/]+/}{}, which would rewrite qwen/qwen3-30b-a3b-instruct-2507 as qwen3-30b-a3b-instruct-2507. Your id set is mixed - bare synap-v1, gpt-oss-20b, qwen3-coder-30b alongside slashed qwen/..., deepseek/..., z-ai/... - so 'model' (use as-is, same as cheaperinference and cheapaimodel) is correct.

Agreed on gpt-oss-20b as the documented default over synap-v1: fixed model, 65,536 stated as fact. It still depends on the fetcher fix above to be honoured.

402 confirmed, and it is already handled: ResponseHandler has a dedicated $status == 402 branch ahead of the generic billing path and classifies it as billing_error. Asserting 401 would fail; assert non-2xx plus billing_error, or skip the auth-negative assertion.

On splitting: keep it together. tests/unit/test_provider_doc_count.pl fails the suite when the registry count and the documented count disagree, and it reads README.md, AGENTS.md, docs/USER_GUIDE.md, docs/FEATURES.md, docs/ARCHITECTURE.md, docs/DEVELOPER_DOCUMENTATION_GUIDE.md and docs/PROVIDERS.md. At 22 it passes today; at 23 it fails at seven assertion sites across six files (ARCHITECTURE.md twice). Docs are not separable from the registry bump. PROVIDERS.md carries no numeric registry count right now, so adding a Synap section there is safe as long as you do not introduce one.

Root Cause Analysis

Confidence: high

Relevant files:

  • lib/CLIO/Core/ModelCapabilitiesManager.pm
  • lib/CLIO/Core/APIManager.pm
  • lib/CLIO/Memory/TokenEstimator.pm
  • lib/CLIO/Core/API/MessageValidator.pm

Relevant functions:

  • _fetch_openai_compatible_capabilities
  • _sanitize_token_limits
  • get_model_capabilities
  • compute_prompt_budget

_fetch_openai_compatible_capabilities extracts context only from context_length/context_window/max_tokens/max_context_tokens/meta.n_ctx/meta.n_ctx_train/top_provider.*, so a feed entry carrying none of those returns context_window => undef. The only two places that consult $provider_def->{max_context_tokens} are the Anthropic parsers (_parse_anthropic_per_model_response, _build_anthropic_caps_from_list_entry), so a registry or provider-defaults.json value never enters the OpenAI-compatible caps hash. APIManager::get_model_capabilities then builds its cache hash with max_context_window_tokens => $caps->{context_window} (undef) and returns it at the MCM branch because the hashref itself is truthy, making the default_context_window($mcm_provider) fallback unreachable. TokenEstimator::compute_prompt_budget therefore sees no context and substitutes DEFAULT_CONTEXT_WINDOW (128000). Measured against the exact hash shape: 97024-token prompt budget for gpt-oss-20b, whose real window is 65536. MessageValidator's $max_prompt does fall back to default_context_window, but that variable is only interpolated into a log_debug line; the actual trim limit is compute_prompt_budget() -> $effective_limit, so the provider default never gates anything. Result is a 400 context_length_exceeded on first request plus a reactive-trim retry.

Affected Areas

  • lib/CLIO/Providers.pm (registry entry)
  • lib/CLIO/Core/model-data/provider-defaults.json
  • lib/CLIO/Core/model-data/provider-mapping.json
  • lib/CLIO/UI/Commands/API/Models.pm (reads top-level context_length / top_provider.* / architecture.input_modalities)
  • tests/unit/test_provider_doc_count.pl (gates doc updates to the registry count)
  • tests/unit/test_providers_flags.pl (@CLOUD_NAMES + default_context_window chain)
  • tests/unit/test_provider_timeout_tiers.pl (@route_providers)
  • tests/unit/test_provider_from_url.pl
  • tests/unit/test_openai_compatible_mcm_url.pl
  • tests/unit/test_api_config_reasoning.pl (requires reasoning_schema.mode on every provider)
  • tests/unit/test_mcm_openrouter_fix.pl (Test 13 requires a provider-mapping entry, not a format value)
  • README.md provider table (already stale: 20 rows, lists SAM which is not in the registry, omits cheaperinference / cheapaimodel / standardcompute)
  • Pre-existing: every OpenAI-compatible provider whose /models lacks top-level context fields, not just Synap

This is an automated analysis. A maintainer will review shortly.

CLIO-Bot avatar Nov 10 '26 18:11 CLIO-Bot

The PR is up: #46.

It follows the cheaperinference template as you described, and includes the stale README/docs provider table and all eight count claims in the same change (22 → 23), so test_provider_doc_count.pl stays green.

Two things from my earlier comment are now resolved rather than just acknowledged:

  • The feed shape is fixed. https://synap402.com/v1/models now carries top-level context_length, top_provider.max_completion_tokens, an architecture object and supported_parameters as a flat array of strings, alongside the existing nested schema_version: 2.4 fields so nothing reading 2.4 breaks. Capability auto-detection no longer renders -. Routers and upstream-served ids stay explicitly unknown rather than guessed, which is why provider-defaults.json still carries explicit values.
  • The default is gpt-oss-20b, 65,536 context, not the synap-v1 router id.

The 402-not-401 behaviour is encoded in a registry comment and the new test asserts no unauthenticated status code, so a future contributor will not add a 401 assertion by habit.

Four unit tests fail on this branch; all four fail identically on base commit 6ca7437 and I have left them alone. The PR body has the side-by-side.

If you would rather review the registry entry on its own, say so and I will split the docs into a second PR.

jimmyplup avatar Nov 10 '26 19:11 jimmyplup

Closed by #46

fewtarius avatar Nov 11 '26 15:11 fewtarius