> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sambanova.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Semantic Kernel integration guide

Semantic Kernel is an open-source development tool that allows you to build agents and integrate the latest AI models into your codebase.

## Prerequisites

Before getting started, ensure you have:

* A [SambaCloud account](http://cloud.sambanova.ai/?utm_source=semantickernel\&utm_medium=external\&utm_campaign=cloud_signup) and API key.
* Python 3.10 or later. Run `python --version` to confirm. Semantic Kernel 1.0 and later requires Python 3.10, and on Python 3.9 `pip` installs the incompatible 0.9 beta instead.

## Installation and setup

1. Create a virtual environment.

   ```bash theme={}
   python -m venv .venv
   source .venv/bin/activate
   ```

   If `python --version` reports 3.9 or earlier, create the environment with an explicit interpreter instead, for example `python3.11 -m venv .venv`.

2. Install the required libraries.

   ```bash theme={}
   pip install "semantic-kernel>=1.44,<2" jupyter ipykernel python-dotenv
   ```

   The upper bound keeps you on the 1.x agent API. Semantic Kernel changed the `ChatCompletionAgent` constructor between 0.9 and 1.0, so pin the major version and test before you upgrade.

3. Create a `.env` file in the same directory and add your credentials. SambaCloud exposes an OpenAI-compatible endpoint, so Semantic Kernel connects to it through the standard OpenAI connector.

   ```bash theme={}
   GLOBAL_LLM_SERVICE="OpenAI"
   OPENAI_API_KEY="<<YOUR_API_KEY>>"
   OPENAI_BASE_URL="https://api.sambanova.ai/v1/"
   OPENAI_CHAT_MODEL_ID="Meta-Llama-3.3-70B-Instruct"
   OPENAI_TEXT_MODEL_ID=""
   OPENAI_EMBEDDING_MODEL_ID=""
   OPENAI_ORG_ID=""
   ```

   Leave the unused IDs empty. `OpenAIChatCompletion` reads these variables at construction time, so the notebook fails at the first agent call if they are missing.

   Pass any [SambaCloud model](/docs/en/models/sambacloud-models) as `OPENAI_CHAT_MODEL_ID`. Agent workflows that give agents tools also need a model that supports [function calling](/docs/en/features/function-calling).

## Example notebook

Follow along with the [Semantic Kernel example notebook](https://github.com/sambanova/integrations/blob/main/semantic_kernel/agents_solving_task.ipynb) to create agents that can function as art directors and copywriters, helping automate creative tasks with advanced AI capabilities.

<Note>
  If the first agent cell fails with `TypeError: ChatCompletionAgent.__init__() got an unexpected keyword argument 'service_id'`, apply the one-line fix in [Troubleshooting](#troubleshooting). The pinned 1.x API no longer accepts `service_id` on the agent constructor.
</Note>

Launch Jupyter from the environment you just created so the notebook runs against it:

```bash theme={}
jupyter lab agents_solving_task.ipynb
```

<Note>
  If you open the notebook in an editor such as VS Code instead, select the interpreter inside `.venv` before you run any cells. Selecting an interpreter does not restart an already-running kernel, so restart the kernel afterward. To confirm which interpreter is actually attached, run `import sys, os; print(sys.executable, os.environ.get("VIRTUAL_ENV"))` in a cell. A `VIRTUAL_ENV` of `None` means the kernel is running outside the environment.
</Note>

## Troubleshooting

<AccordionGroup>
  <Accordion title="ImportError: cannot import name 'Url' from 'pydantic.networks'">
    You installed the 0.9 beta, which is the last release that supports Python 3.9. On Python 3.9, `pip` selects it silently because 1.0 and later require Python 3.10.

    Confirm `python --version` is 3.10 or later, then recreate the environment and reinstall with the bounded command in [Installation and setup](#installation-and-setup). Upgrading in place does not help, because no 1.x release installs on Python 3.9.
  </Accordion>

  <Accordion title="TypeError: ChatCompletionAgent.__init__() got an unexpected keyword argument 'service_id'">
    `ChatCompletionAgent` accepted `service_id` in 0.9. In 1.0 and later, the agent takes a configured `kernel` or `service` instead.

    Remove the `service_id` argument from the agent constructor. Keep it on `OpenAIChatCompletion`, which still accepts it.
  </Accordion>

  <Accordion title="ModuleNotFoundError: No module named 'semantic_kernel' in a notebook">
    The notebook kernel is running outside your virtual environment, usually because the editor started it from a different interpreter.

    Restart the kernel after selecting the environment, then verify with the check in the note above. Launching `jupyter lab` from the activated environment avoids the problem entirely.
  </Accordion>

  <Accordion title="401 from the endpoint">
    `OPENAI_API_KEY` is unset, expired, or the `.env` file is not in the directory the notebook runs from.

    Confirm the key works with a completion request:

    ```bash theme={}
    curl -s -o /dev/null -w "%{http_code}\n" https://api.sambanova.ai/v1/chat/completions \
      -H "Authorization: Bearer $OPENAI_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"model":"Meta-Llama-3.3-70B-Instruct","messages":[{"role":"user","content":"hi"}],"max_tokens":3}'
    ```

    A `200` confirms the key is valid. Test against a completion request rather than a model listing, because the models endpoint answers without checking credentials.
  </Accordion>
</AccordionGroup>

## Additional resources

* [Semantic Kernel documentation](https://learn.microsoft.com/en-us/semantic-kernel/)
* [Function calling](/docs/en/features/function-calling)
* [SambaCloud models](/docs/en/models/sambacloud-models)
