Appearance
Kimi API 不支持通过 URL 直接访问网页内容
问题
通过 Kimi API 让模型总结某个 URL 的网页内容,收到"无法访问网页内容"的提示。但在 kimi.ai 网页端却能正常访问和总结。
python
response = client.chat.completions.create(
model="kimi-k2.6",
messages=[{"role": "user", "content": "总结这个网页:https://example.com/article"}],
)
# 模型回复:无法访问该链接...解决方案
Kimi API 默认不会主动访问网络链接,和 kimi.ai 网页端不同。有两种方式处理:
方式一:自行抓取网页内容再传给 API(推荐)
python
import httpx
from bs4 import BeautifulSoup
url = "https://example.com/article"
html = httpx.get(url, follow_redirects=True).text
text = BeautifulSoup(html, "html.parser").get_text(separator="\n", strip=True)[:8000]
response = client.chat.completions.create(
model="kimi-k2.6",
messages=[
{"role": "user", "content": f"总结以下内容:\n\n{text}"}
],
)方式二:使用 $web_search 内置工具搜索实时内容
python
response = client.chat.completions.create(
model="kimi-k2.6",
tools=[{"type": "builtin_function", "function": {"name": "$web_search"}}],
messages=[{"role": "user", "content": "搜索并总结 example.com 的最新内容"}],
)注意 $web_search 按调用次数收费(¥0.03/次),适合需要实时信息的场景,不适合抓取固定 URL 的已知内容。