Skip to content

Can't Use Kimi API Key in CAI #447

@Ming-katana

Description

@Ming-katana

I'm trying to use kimi k2.6 model provided by Moonshot AI, I have already include MOONSHOT_API_KEY & MOONSHOT_BASE_URL but i still hit errors. Anyone know how to fix?

This is my .env:

OPENAI_API_KEY=''
MOONSHOT_API_KEY="sk-xxx"
MOONSHOT_BASE_URL="https://api.moonshot.ai/v1"

#extra
ANTHROPIC_API_KEY=""
OLLAMA=""
PROMPT_TOOLKIT_NO_CPR=1
CAI_STREAM=false
CAI_MODEL='moonshot/kimi-k2.6'

Errors show below:

ERROR:cai.cli:Error in main loop: litellm.APIError: APIError: OpenAIException - Connection error.
Traceback (most recent call last):
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/httpx/_transports/default.py", line 101, in map_httpcore_exceptions
yield
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/httpx/_transports/default.py", line 394, in handle_async_request
resp = await self._pool.handle_async_request(req)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/httpcore/_async/connection_pool.py", line 256, in handle_async_request
raise exc from None
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/httpcore/_async/connection_pool.py", line 236, in handle_async_request
response = await connection.handle_async_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/httpcore/_async/connection.py", line 101, in handle_async_request
raise exc
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/httpcore/_async/connection.py", line 78, in handle_async_request
stream = await self._connect(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/httpcore/_async/connection.py", line 124, in _connect
stream = await self._network_backend.connect_tcp(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/httpcore/_backends/auto.py", line 31, in connect_tcp
return await self._backend.connect_tcp(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/httpcore/_backends/anyio.py", line 113, in connect_tcp
with map_exceptions(exc_map):
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/contextlib.py", line 158, in exit
self.gen.throw(value)
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
raise to_exc(exc) from exc
httpcore.ConnectError: All connection attempts failed

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/openai/_base_client.py", line 1538, in _request
response = await self._client.send(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/httpx/_client.py", line 1629, in send
response = await self._send_handling_auth(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/httpx/_client.py", line 1657, in _send_handling_auth
response = await self._send_handling_redirects(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/httpx/_client.py", line 1694, in _send_handling_redirects
response = await self._send_single_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/httpx/_client.py", line 1730, in _send_single_request
response = await transport.handle_async_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/httpx/_transports/default.py", line 393, in handle_async_request
with map_httpcore_exceptions():
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/contextlib.py", line 158, in exit
self.gen.throw(value)
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/httpx/_transports/default.py", line 118, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ConnectError: All connection attempts failed

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/litellm/llms/openai/openai.py", line 790, in acompletion
headers, response = await self.make_openai_chat_completion_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/litellm/litellm_core_utils/logging_utils.py", line 135, in async_wrapper
result = await func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/litellm/llms/openai/openai.py", line 436, in make_openai_chat_completion_request
raise e
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/litellm/llms/openai/openai.py", line 418, in make_openai_chat_completion_request
await openai_aclient.chat.completions.with_raw_response.create(
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/openai/_legacy_response.py", line 381, in wrapped
return cast(LegacyAPIResponse[R], await func(*args, **kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/openai/resources/chat/completions/completions.py", line 2032, in create
return await self._post(
^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/openai/_base_client.py", line 1805, in post
return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/openai/_base_client.py", line 1495, in request
return await self._request(
^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/openai/_base_client.py", line 1562, in _request
return await self._retry_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/openai/_base_client.py", line 1632, in _retry_request
return await self._request(
^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/openai/_base_client.py", line 1562, in _request
return await self._retry_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/openai/_base_client.py", line 1632, in _retry_request
return await self._request(
^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/openai/_base_client.py", line 1572, in _request
raise APIConnectionError(request=request) from err
openai.APIConnectionError: Connection error.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/litellm/main.py", line 507, in acompletion
response = await init_response
^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/litellm/llms/openai/openai.py", line 837, in acompletion
raise OpenAIError(
litellm.llms.openai.common_utils.OpenAIError: Connection error.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/cai/cli.py", line 1644, in run_cai_cli
response = asyncio.run(Runner.run(agent, conversation_input))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/runners.py", line 195, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/cai/sdk/agents/run.py", line 239, in run
input_guardrail_results, turn_result = await asyncio.gather(
^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/cai/sdk/agents/run.py", line 847, in _run_single_turn
new_response = await cls._get_new_response(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/cai/sdk/agents/run.py", line 1046, in _get_new_response
new_response = await model.get_response(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/cai/sdk/agents/models/openai_chatcompletions.py", line 700, in get_response
response = await self._fetch_response(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/cai/sdk/agents/models/openai_chatcompletions.py", line 3128, in _fetch_response
return await self._fetch_response_litellm_ollama(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/cai/sdk/agents/models/openai_chatcompletions.py", line 3463, in _fetch_response_litellm_ollama
return await litellm.acompletion(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/litellm/utils.py", line 1461, in wrapper_async
raise e
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/litellm/utils.py", line 1322, in wrapper_async
result = await original_function(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/litellm/main.py", line 526, in acompletion
raise exception_type(
^^^^^^^^^^^^^^^
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2224, in exception_type
raise e
File "/home/kali/Desktop/CAI-n/cai_env/lib/python3.12/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 459, in exception_type
raise APIError(
litellm.exceptions.APIError: litellm.APIError: APIError: OpenAIException - Connection error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions