MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / resolve_extra_headers

Function resolve_extra_headers

openkb/config.py:105–144  ·  view source on GitHub ↗

Resolve the optional ``extra_headers:`` config key into a str→str dict. Some LiteLLM providers need extra HTTP headers on every request (e.g. GitHub Copilot's ``Editor-Version`` IDE-auth headers). Users opt in via an ``extra_headers:`` mapping in config.yaml; the result is forwarded to

(config: dict)

Source from the content-addressed store, hash-verified

103
104
105def resolve_extra_headers(config: dict) -> dict[str, str]:
106 """Resolve the optional ``extra_headers:`` config key into a str→str dict.
107
108 Some LiteLLM providers need extra HTTP headers on every request (e.g.
109 GitHub Copilot's ``Editor-Version`` IDE-auth headers). Users opt in via
110 an ``extra_headers:`` mapping in config.yaml; the result is forwarded to
111 LiteLLM's ``extra_headers`` parameter on all LLM calls.
112
113 Values are stringified (YAML may parse version-like values as numbers).
114 Entries with a non-string/empty key or a non-scalar value are skipped.
115 A non-mapping ``extra_headers`` is ignored entirely. Warnings are logged
116 only when the key was present but malformed.
117 """
118 raw = config.get("extra_headers")
119 if raw is None:
120 return {}
121 if not isinstance(raw, dict):
122 logger.warning(
123 "config: 'extra_headers' must be a mapping of header name to "
124 "value, got %s — ignoring it.",
125 type(raw).__name__,
126 )
127 return {}
128 headers: dict[str, str] = {}
129 for key, value in raw.items():
130 if not isinstance(key, str) or not key.strip():
131 logger.warning(
132 "config: skipping 'extra_headers' entry with non-string or empty key: %r",
133 key,
134 )
135 continue
136 if value is None or not isinstance(value, (str, int, float, bool)):
137 logger.warning(
138 "config: skipping 'extra_headers' entry %r with non-scalar value: %r",
139 key,
140 value,
141 )
142 continue
143 headers[key.strip()] = str(value)
144 return headers
145
146
147def resolve_timeout(config: dict) -> float | None:

Calls 1

getMethod · 0.45