FIM Gate Docs
SDKs

OpenAI SDK Integration

Connect to FIM Gate with the official OpenAI SDKs, covering Python, Node.js, .NET, Java, and Go.

FIM Gate is fully compatible with the OpenAI API protocol. Just point the SDK's base URL at FIM Gate and use an API key issued by FIM Gate — everything else works exactly as it does when connecting to OpenAI directly.

Integration requires only two settings:

SettingValue
Base URLhttps://api.gate.fim.ai/v1
API keyCreated in the FIM Gate Console (referred to as $FIM_API_KEY below)

Configuring the API key

We recommend passing the key via an environment variable instead of hardcoding it in code or committing it to a repository. All official OpenAI SDKs automatically read the OPENAI_API_KEY environment variable.

# macOS / Linux
export OPENAI_API_KEY="$FIM_API_KEY"
# Windows
setx OPENAI_API_KEY "$FIM_API_KEY"

Replace $FIM_API_KEY with the key you created in the FIM Gate Console. If you must put the key directly in code, make sure that code is never shared or published.

Python

Install the official SDK:

pip install openai

Point the client at FIM Gate via the base_url parameter when initializing:

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.gate.fim.ai/v1",
    api_key=os.getenv("OPENAI_API_KEY"),
)

response = client.chat.completions.create(
    model="gpt-4.1",
    messages=[
        {"role": "user", "content": "Describe a black hole in one sentence."},
    ],
)

print(response.choices[0].message.content)

Save it as main.py and run python main.py to see the model's response.

Node.js

Works with server-side JavaScript runtimes such as Node.js, Deno, and Bun:

pnpm add openai

Pass baseURL (note the casing) when constructing the client:

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
  baseURL: "https://api.gate.fim.ai/v1",
});

const response = await client.responses.create({
  model: "gpt-4.1",
  input: "Describe a black hole in one sentence.",
});

console.log(response.output_text);

Save it as main.mjs and run node main.mjs. Both the Responses API and the Chat Completions API are supported.

.NET

Install the official package via NuGet:

dotnet add package OpenAI

Specify the FIM Gate address via OpenAIClientOptions.Endpoint:

using System.ClientModel;
using OpenAI;
using OpenAI.Chat;

ChatClient client = new(
    model: "gpt-4.1",
    credential: new ApiKeyCredential(
        Environment.GetEnvironmentVariable("OPENAI_API_KEY")!),
    options: new OpenAIClientOptions
    {
        Endpoint = new Uri("https://api.gate.fim.ai/v1"),
    });

ChatCompletion completion = client.CompleteChat("Describe a black hole in one sentence.");
Console.WriteLine(completion.Content[0].Text);

Java

Add the Maven dependency to pom.xml:

<dependency>
    <groupId>com.openai</groupId>
    <artifactId>openai-java</artifactId>
    <version>0.31.0</version>
</dependency>

The Java SDK's fromEnv() reads environment variables such as OPENAI_API_KEY, OPENAI_ORG_ID, and OPENAI_PROJECT_ID. To connect to FIM Gate, additionally set OPENAI_BASE_URL:

export OPENAI_BASE_URL="https://api.gate.fim.ai/v1"
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.ChatCompletion;
import com.openai.models.ChatCompletionCreateParams;

OpenAIClient client = OpenAIOkHttpClient.fromEnv();

ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
        .model("gpt-4.1")
        .addUserMessage("Describe a black hole in one sentence.")
        .build();

ChatCompletion completion = client.chat().completions().create(params);

You can also skip environment variables and call baseUrl("https://api.gate.fim.ai/v1") and apiKey(...) explicitly on the builder.

Go

Get the official Go SDK:

go get github.com/openai/openai-go

Point it at FIM Gate via option.WithBaseURL:

package main

import (
	"context"
	"fmt"

	"github.com/openai/openai-go"
	"github.com/openai/openai-go/option"
)

func main() {
	client := openai.NewClient(
		option.WithAPIKey("$FIM_API_KEY"), // reads the OPENAI_API_KEY environment variable by default
		option.WithBaseURL("https://api.gate.fim.ai/v1"),
	)

	completion, err := client.Chat.Completions.New(context.TODO(),
		openai.ChatCompletionNewParams{
			Model: openai.ChatModelGPT4o,
			Messages: []openai.ChatCompletionMessageParamUnion{
				openai.UserMessage("Describe a black hole in one sentence."),
			},
		})
	if err != nil {
		panic(err)
	}

	fmt.Println(completion.Choices[0].Message.Content)
}

Other languages

Beyond the official SDKs above, the developer community maintains many OpenAI-compatible client libraries for PHP, Ruby, Rust, Kotlin, Swift, and more. Any library that supports a custom base URL can connect to FIM Gate; for the API definitions, see OpenAI's public OpenAPI specification repository. Community libraries have not undergone official security audits — evaluate them yourself before use.