Skip to content

Quickstart

Follow these 3 steps to make your first request through the AI Gateway.

Step #1: Create an Access Key

Go to the Access Keys page in the SocketXP Web Portal and create a new Access Key.

The raw key, in the format sxp_<id>_v1_<secret>, is shown to you exactly once at creation, so copy it somewhere safe. SocketXP doesn't store the raw key, and cannot show it to you again after that.

Note

You can optionally attach an Access Key Policy to restrict which providers and models this key is allowed to use. A key with no policy attached can use any provider or model. See Access Keys and Policies.

Export it as an environment variable so the examples below can use it:

export AI_GATEWAY_ACCESS_KEY="sxp_xxxxxxxx_v1_xxxxxxxxxxxxxxxx"

Step #2: Register a provider

You have two options here, and you're free to use both at once.

To use a built-in provider such as OpenAI, Anthropic, or Google, register your own API key for that provider under AI Providers → BYOK Keys in the SocketXP Web Portal. This key is encrypted at rest and never exposed to your client applications; the gateway simply uses it on your behalf. See Built-in Providers.

To use your own self-hosted model server instead, register a Custom Provider under AI Providers, pointing it at a SocketXP tunnel connected to your Ollama, vLLM, or LM Studio instance. See Custom Providers.

Step #3: Call the gateway

Point any OpenAI SDK (or plain HTTP) at https://ai-gateway.socketxp.com/v1, using your Access Key as the API key, and set model to the model you want to use. The gateway resolves the right provider automatically from the model field.

import os

from openai import OpenAI

client = OpenAI(
    base_url="https://ai-gateway.socketxp.com/v1",
    api_key=os.environ["AI_GATEWAY_ACCESS_KEY"],
)

response = client.chat.completions.create(
    model="gpt-5.6-luna",
    messages=[{"role": "user", "content": "What is the capital of France?"}],
)
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://ai-gateway.socketxp.com/v1",
  apiKey: process.env.AI_GATEWAY_ACCESS_KEY,
});

const response = await client.chat.completions.create({
  model: "gpt-5.6-luna",
  messages: [{ role: "user", content: "What is the capital of France?" }],
});
package main

import (
    "context"
    "fmt"
    "os"

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

func main() {
    client := openai.NewClient(
        option.WithBaseURL("https://ai-gateway.socketxp.com/v1"),
        option.WithAPIKey(os.Getenv("AI_GATEWAY_ACCESS_KEY")),
    )

    resp, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
        Model: "gpt-5.6-luna",
        Messages: []openai.ChatCompletionMessageParamUnion{
            openai.UserMessage("What is the capital of France?"),
        },
    })
    if err != nil {
        panic(err)
    }
    fmt.Println(resp.Choices[0].Message.Content)
}
curl https://ai-gateway.socketxp.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $AI_GATEWAY_ACCESS_KEY" \
  -d '{
    "model": "gpt-5.6-luna",
    "messages": [{"role": "user", "content": "What is the capital of France?"}]
  }'
import os

from openai import OpenAI

client = OpenAI(
    base_url="https://ai-gateway.socketxp.com/v1",
    api_key=os.environ["AI_GATEWAY_ACCESS_KEY"],
)

response = client.chat.completions.create(
    model="claude-sonnet-5",
    messages=[{"role": "user", "content": "What is the capital of France?"}],
)
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://ai-gateway.socketxp.com/v1",
  apiKey: process.env.AI_GATEWAY_ACCESS_KEY,
});

const response = await client.chat.completions.create({
  model: "claude-sonnet-5",
  messages: [{ role: "user", content: "What is the capital of France?" }],
});
package main

import (
    "context"
    "fmt"
    "os"

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

func main() {
    client := openai.NewClient(
        option.WithBaseURL("https://ai-gateway.socketxp.com/v1"),
        option.WithAPIKey(os.Getenv("AI_GATEWAY_ACCESS_KEY")),
    )

    resp, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
        Model: "claude-sonnet-5",
        Messages: []openai.ChatCompletionMessageParamUnion{
            openai.UserMessage("What is the capital of France?"),
        },
    })
    if err != nil {
        panic(err)
    }
    fmt.Println(resp.Choices[0].Message.Content)
}
curl https://ai-gateway.socketxp.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $AI_GATEWAY_ACCESS_KEY" \
  -d '{
    "model": "claude-sonnet-5",
    "messages": [{"role": "user", "content": "What is the capital of France?"}]
  }'
import os

from openai import OpenAI

client = OpenAI(
    base_url="https://ai-gateway.socketxp.com/v1",
    api_key=os.environ["AI_GATEWAY_ACCESS_KEY"],
)

response = client.chat.completions.create(
    model="gemini-3.7-flash",
    messages=[{"role": "user", "content": "What is the capital of France?"}],
)
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://ai-gateway.socketxp.com/v1",
  apiKey: process.env.AI_GATEWAY_ACCESS_KEY,
});

const response = await client.chat.completions.create({
  model: "gemini-3.7-flash",
  messages: [{ role: "user", content: "What is the capital of France?" }],
});
package main

import (
    "context"
    "fmt"
    "os"

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

func main() {
    client := openai.NewClient(
        option.WithBaseURL("https://ai-gateway.socketxp.com/v1"),
        option.WithAPIKey(os.Getenv("AI_GATEWAY_ACCESS_KEY")),
    )

    resp, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{
        Model: "gemini-3.7-flash",
        Messages: []openai.ChatCompletionMessageParamUnion{
            openai.UserMessage("What is the capital of France?"),
        },
    })
    if err != nil {
        panic(err)
    }
    fmt.Println(resp.Choices[0].Message.Content)
}
curl https://ai-gateway.socketxp.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $AI_GATEWAY_ACCESS_KEY" \
  -d '{
    "model": "gemini-3.7-flash",
    "messages": [{"role": "user", "content": "What is the capital of France?"}]
  }'

Notice that only the model field changes across providers. The base_url and your Access Key stay exactly the same no matter which one you call.

Go SDK note

The Go example uses the community github.com/openai/openai-go SDK and is meant to be illustrative. Its API surface has moved across versions, so verify it against that package's current documentation before relying on it. The Python and JavaScript examples use the official, stable OpenAI SDKs.