# API Access

uniGPT provides an **OpenAI-compatible API** that allows researchers and developers to integrate AI models into their own applications, scripts, and workflows.

The API is available at:

```
https://gpt.uni-muenster.de/v1
```

## Getting an API Key

To use the API, you need an API key (starting with `sk-...`). API keys are currently available for two use cases:

### Research Projects

API keys for research projects are issued upon request. Contact the uniGPT team via our support channel:

[**uniGPT Support on Mattermost**](<https://mattermost.uni-muenster.de/wwu/channels/unigpt>)

Please briefly describe your project and intended usage so we can set appropriate quotas.

### AI-Assisted Coding (OpenCode, Roo Code, etc.)

API keys for use with coding assistants are available through a **self-service portal** at **[https://gpt-api.uni-muenster.de](<https://gpt-api.uni-muenster.de>)**, where you can generate your own key without manual approval. The portal is open to all employees. A small guide for OpenCode and VSCode is shown [below](<#using-coding-assistants>).

Currently the following models are enabled for all employees via the portal:

- **DeepSeek-v4-flash**
- **Qwen3.8-27B**

Additional models are enabled on request — contact the team via the support channel. If you generated your key before a model was added, you may need to **regenerate your key** to pick it up.

> [!WARNING]
>
> **Beta**
>
> The self-service portal is currently in **beta**. Access and functionality may change. Stay tuned for announcements in the support channel.

## Using the Python OpenAI Client

Install the OpenAI Python library:

```
pip install openai
```

### Basic Example

```
from openai import OpenAI

client = OpenAI(
    api_key="sk-YOUR_API_KEY",
    base_url="https://gpt.uni-muenster.de/v1"
)

completion = client.chat.completions.create(
    model="gemma-4-31B-it",
    messages=[
        {"role": "user", "content": "What is the capital of France?"}
    ]
)

print(completion.choices[0].message.content)
```

### Streaming Example

```
stream = client.chat.completions.create(
    model="gemma-4-31B-it",
    messages=[{"role": "user", "content": "Explain quantum computing briefly."}],
    stream=True,
)

for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")
```

## Using curl

```
curl https://gpt.uni-muenster.de/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-YOUR_API_KEY" \
  -d '{
    "model": "gemma-4-31B-it",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'
```

## Checking Your Key &amp; Quotas

You can inspect your API key and its quotas using the `/key/info` endpoint:

```
curl https://gpt.uni-muenster.de/key/info \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-ENTER-KEY-HERE"
```

This returns information about your key and the configured quotas/limits.

## Limits, Concurrency &amp; Caching

- **Parallel requests**: By default, each API key allows **4 parallel requests**. Contact the team if you need more.
- **Input caching**: Prompt caching is enabled, but the discount is **not yet billed** — you currently pay the full input price even for cached tokens.
- **Reasoning**: Reasoning is returned via the OpenAI Chat Completions format as the `reasoning_content` field alongside `content`.

> [!NOTE]
>
> **Limits are separate from the chat balance**
>
> The API rate limits are managed independently of the token balance shown in the web chat interface. Your API key's quotas are queryable via `/key/info`.

## Available Models via API

You can use any of the **internal** models listed on the [Available Models](<https://gpt.uni-muenster.de/docs/available-models/index.md>) page by specifying their name in the `model` parameter, including specialized models such as `medgemma-1.5-4b-it` for medical text and image tasks. Through the self-service portal, **DeepSeek-v4-flash** and **Qwen3.8-27B** are currently enabled for all employees; additional models are enabled on request.

> [!WARNING]
>
> **Model access**
>
> Access to a model is granted per team/group. If you receive the error `team not allowed to access model`, the requested model is not enabled for your account.

> [!TIP]
>
> **Drop-in replacement**
>
> Since the API is OpenAI-compatible, you can use it as a drop-in replacement in any tool or library that supports the OpenAI API — just change the `base_url` and `api_key`.

## Using Coding Assistants

You can connect uniGPT to your ide and coding agents via the OpenAI-compatible API. You will need an [API key](<#getting-an-api-key>) from the self-service portal.

### Visual Studio Code

Since version 1.104, Visual Studio Code can connect to uniGPT in the **built-in Chat** view via a custom provider. No extra extension is required.

This uses VS Code's [custom endpoint](<https://code.visualstudio.com/docs/agent-customization/language-models#_add-a-custom-endpoint-model>) provider. Chat works with your uniGPT API key and does **not** require a GitHub Copilot plan.

1. Open the Command Palette (`Ctrl+Shift+P` / `Cmd+Shift+P`) and run **Chat: Manage Language Models**.
2. Select **Add Models**, then **Custom Endpoint**.
3. Enter a group name such as `uniGPT` and paste your uniGPT API key when prompted.
4. Select **Chat Completions** as the API type.
5. VS Code opens the `chatLanguageModels.json` file. Fill in the model fields as shown below and save it. **Do not replace** the `apiKey` value. Keep the `${input:...}` variable that VS Code generated.

```
[
  {
    "name": "uniGPT",
    "vendor": "customendpoint",
    "apiKey": "${input:chat.lm.secret.xxxxxxxxx}",
    "apiType": "chat-completions",
    "models": [
      {
        "id": "DeepSeek-V4-Flash",
        "name": "uniGPT DeepSeek V4 Flash",
        "url": "https://gpt.uni-muenster.de/v1/chat/completions",
        "toolCalling": true,
        "vision": true,
        "maxInputTokens": 128000,
        "maxOutputTokens": 8000
      },
      {
        "id": "Qwen3.8-27B",
        "name": "uniGPT Qwen3.8 27B",
        "url": "https://gpt.uni-muenster.de/v1/chat/completions",
        "toolCalling": true,
        "vision": false,
        "maxInputTokens": 128000,
        "maxOutputTokens": 8000
      }
    ]
  }
]
```

Set `id` to an **internal** model name from the [Available Models](<https://gpt.uni-muenster.de/docs/available-models/index.md>) page. You can add further objects to the `models` array to switch between them in the picker.

Use `maxInputTokens` **128000** and `maxOutputTokens` **8000**. For a multimodal model such as DeepSeek V4 Flash, set `"vision": true`.

If the model does not appear in the picker immediately, restart VS Code.

### OpenCode

OpenCode can use uniGPT as a [custom OpenAI-compatible provider](<https://opencode.ai/docs/providers/#custom-provider>). You need an [API key](<#getting-an-api-key>) from the self-service portal.

1. Start OpenCode and run **`/connect`**.
2. Select **Other**, then enter `unigpt` as the provider ID.
3. Paste your uniGPT API key when prompted. OpenCode stores it in its auth file. Do **not** put the key in `opencode.json`.
4. Create or update your OpenCode config (`~/.config/opencode/opencode.json` for all projects, or `opencode.json` in a project root):

```
{
  "$schema": "https://opencode.ai/config.json",
  "model": "unigpt/DeepSeek-V4-Flash",
  "provider": {
    "unigpt": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "uniGPT",
      "options": {
        "baseURL": "https://gpt.uni-muenster.de/v1"
      },
      "models": {
        "DeepSeek-V4-Flash": {
          "name": "uniGPT DeepSeek V4 Flash",
          "limit": {
            "context": 128000,
            "output": 8000
          }
        },
        "Qwen3.8-27B": {
          "name": "uniGPT Qwen3.8 27B",
          "limit": {
            "context": 128000,
            "output": 8000
          }
        }
      }
    }
  }
}
```

The provider ID in `/connect` must match the key in `provider` (`unigpt`). Use `@ai-sdk/openai-compatible` because uniGPT speaks the Chat Completions API.

If you already have an `opencode.json`, merge the `provider.unigpt` block into it rather than replacing the whole file.

1. Run **`/models`** and select **uniGPT DeepSeek V4 Flash**.
