Skip to content

Your server

Work on your server

Let SwisserAI change the files on the machine that runs your server, from its terminal. Tested with OpenCode on Linux.

Why on the server

Most FiveM servers run on a Linux or Windows machine you reach over SSH or remote desktop. Editing there usually means: download the file, change it, upload it, restart. With a coding agent in the server terminal, SwisserAI changes the files where they run, and you only restart the resource.

The tool for that is OpenCode, a free, open-source coding agent for the terminal. It connects to SwisserAI with an API key. We tested the setup below on a Linux server with OpenCode 1.19: the task "change the garage blip sprite to 50" was done in 22 seconds.

Create an API key

  1. 1

    Open API access in your account

    On ai.swisser.dev open your account settings and scroll to API access. Click Create Key.

    1. 1. Create Key: for OpenCode and other tools
  2. 2

    Give it a name

    Any name you will recognise later, for example the name of the server.

    1. 1. Key name: any name you recognise later
    2. 2. Create Key
  3. 3

    Copy the key right away

    The key starts with sws-ai_ and is shown only once. Copy it into a password manager. If you lose it, delete the key and create a new one.

Treat the key like a password

Anyone with the key can spend your credits. Do not paste it into a resource, a Discord message or a file that goes into Git. If it leaks, delete it in the account settings; it stops working immediately.

Install OpenCode

OpenCode installs with npm, which comes with Node.js. On the server, run:

npm install -g opencode-ai

Check that it works:

opencode --version

Other ways to install it are on the OpenCode website.

Connect OpenCode to SwisserAI

Create a file named opencode.json in your server folder, next to server.cfg, with this content. It is the same for everyone; the key is not in it.

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "swisserai": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "SwisserAI",
      "options": {
        "baseURL": "https://ai.swisser.dev/v1",
        "apiKey": "{env:SWISSERAI_API_KEY}"
      },
      "models": {
        "swisserai-free": { "name": "SwisserAI", "limit": { "context": 131072, "output": 8192 } },
        "swisserai-premium": { "name": "SwisserAI Premium", "limit": { "context": 262144, "output": 65536 } }
      }
    }
  },
  "model": "swisserai/swisserai-free"
}

The last line picks the model. swisserai-free works for every account. With a plan, change it to swisserai/swisserai-premium for more room on long tasks.

Then put your API key into the environment variable SWISSERAI_API_KEY:

export SWISSERAI_API_KEY="sws-ai_your_key_here"

That lasts until you log out. To keep it, add the same line to the end of ~/.bashrc.

To use SwisserAI in every folder instead of one, put opencode.json into ~/.config/opencode/ instead.

Run your first task

Go into your server folder and start OpenCode there. It only sees the folder you start it in.

cd /home/fivem/server
opencode

Type your task the same way as in the extension, with the resource name. To run one task without the interactive screen, for example from a script, use opencode run:

opencode run "In sw-garages, change the garage blip sprite to 50."

OpenCode prints which files it read and the change it made. Then restart the resource in the server console:

refresh
ensure sw-garages

Before you let it touch a live server

In our test, OpenCode saved the edit without asking first. That is fast, but on a server players use you want a way back. Put the resources folder in Git once:

cd /home/fivem/server/resources
git init
git add .
git commit -m "before AI changes"
  • git diff shows exactly what the agent changed.
  • git checkout -- . undoes all changes since the last commit.
  • Commit again after each change you keep.

Start OpenCode in the folder of the one resource you work on rather than the whole server when you can. It reads less, costs less and cannot touch anything else.