Language
Inference Space Docs

Client Integrations (Claude Code / Codex CLI / SDK)

Point Codex CLI, Claude Code, OpenCode, and the OpenAI / Anthropic SDKs at Inference Space with one-line installers or manual configuration.

To connect an existing AI client to Inference Space, change two things: the Base URL and the API Key (starts with gk_, created in the console). One Key works with both the OpenAI and Anthropic protocols.

ProtocolBase URLUsed by
OpenAI (Responses / Chat Completions)https://ai.inf.space/v1Codex CLI, OpenAI SDK, OpenCode
Anthropic (Messages)https://ai.inf.space (no /v1)Claude Code, Anthropic SDK

Examples on this page use the Global region host ai.inf.space. To use the China region, change only the host: https://cn.inf.space (accelerated route) or https://global.inf.space (international route). A China-region Key works on both cn. and global.; a Global-region Key works only on ai.inf.space. See Regions and routes.

If this is your first setup, or you need to install Node.js, the Codex desktop app, or the CC Switch GUI, start with Quick start.

Codex CLI

Codex calls the Responses protocol (/v1/responses). The installer writes an inference-space provider into ~/.codex/config.toml and stores the Key in a dedicated INFERENCE_SPACE_API_KEY environment variable. Re-running it does not create duplicate entries.

curl -fsSL https://docs.inf.space/install/codex.sh | bash -s -- --key gk_YOUR_KEY --route global
# Switch routes: --route cn-accel (China, accelerated; the default) or --route cn-global (China, international)
iwr https://docs.inf.space/install/codex.ps1 -OutFile setup-codex.ps1
.\setup-codex.ps1 -Key gk_YOUR_KEY -Route global
# Switch routes: -Route cn-accel (China, accelerated; the default) or -Route cn-global (China, international)

Open a new terminal and run codex. The resulting configuration is equivalent to:

model_provider = "inference-space"
model = "gpt-5.6-sol"
model_reasoning_effort = "medium"
preferred_auth_method = "apikey"

[model_providers.inference-space]
name = "Inference Space"
# Global region; China region is https://cn.inf.space/v1 (accelerated) or https://global.inf.space/v1 (international)
base_url = "https://ai.inf.space/v1"
env_key = "INFERENCE_SPACE_API_KEY"
wire_api = "responses"
request_max_retries = 0
stream_max_retries = 0

If you configure it by hand:

  • Keep the top-level model_provider = "inference-space". Without it Codex uses its built-in openai provider and gets 401.
  • model can be any model enabled for your Key.
  • Store the gateway Key in its own INFERENCE_SPACE_API_KEY. Do not reuse OPENAI_API_KEY, or it will clash with your real OpenAI Key.

Claude Code

Claude Code calls the Anthropic protocol (/v1/messages). The installer merges the Base URL and Key into the env block of ~/.claude/settings.json and keeps any other settings in the file.

curl -fsSL https://docs.inf.space/install/claude.sh | bash -s -- --key gk_YOUR_KEY --route global
# Switch routes: --route cn-accel (China, accelerated; the default) or --route cn-global (China, international)
iwr https://docs.inf.space/install/claude.ps1 -OutFile setup-claude.ps1
.\setup-claude.ps1 -Key gk_YOUR_KEY -Route global
# Switch routes: -Route cn-accel (China, accelerated; the default) or -Route cn-global (China, international)

What it writes is equivalent to:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://ai.inf.space",
    "ANTHROPIC_AUTH_TOKEN": "gk_YOUR_KEY"
  }
}
  • ANTHROPIC_BASE_URL has no /v1; Claude Code appends /v1/messages itself.
  • To try it in the current terminal only, export these two variables and run claude.

An ANTHROPIC_API_KEY exported in your shell, or an ANTHROPIC_BASE_URL pointing elsewhere, takes precedence over settings.json and makes Claude Code bypass the gateway. The installer warns you when it detects this; run unset ANTHROPIC_API_KEY / unset ANTHROPIC_BASE_URL as prompted.

OpenCode

One ~/.config/opencode/opencode.json configures both the OpenAI and Anthropic protocols:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "openai": {
      "options": { "baseURL": "https://ai.inf.space/v1", "apiKey": "gk_YOUR_KEY" }
    },
    "anthropic": {
      "npm": "@ai-sdk/anthropic",
      "options": { "baseURL": "https://ai.inf.space", "apiKey": "gk_YOUR_KEY" }
    }
  }
}

OpenAI SDK

Set base_url to https://ai.inf.space/v1 and api_key to your gateway Key. You can call Chat Completions and Responses.

import os
from openai import OpenAI

client = OpenAI(
    # Global region; China region is https://cn.inf.space/v1 (accelerated) or https://global.inf.space/v1 (international)
    base_url="https://ai.inf.space/v1",
    api_key=os.environ["INFERENCE_SPACE_API_KEY"],  # gateway Key starting with gk_
)

resp = client.chat.completions.create(
    model="gpt-5.6-sol",  # replace with a model enabled for your Key
    messages=[{"role": "user", "content": "Introduce yourself in one sentence."}],
)
print(resp.choices[0].message.content)
import OpenAI from "openai";

const client = new OpenAI({
  // Global region; China region is https://cn.inf.space/v1 (accelerated) or https://global.inf.space/v1 (international)
  baseURL: "https://ai.inf.space/v1",
  apiKey: process.env.INFERENCE_SPACE_API_KEY, // gateway Key starting with gk_
});

const resp = await client.chat.completions.create({
  model: "gpt-5.6-sol", // replace with a model enabled for your Key
  messages: [{ role: "user", content: "Introduce yourself in one sentence." }],
});
console.log(resp.choices[0].message.content);

Anthropic SDK

Set base_url to https://ai.inf.space (no /v1). The gateway accepts both x-api-key and Authorization: Bearer, so either api_key or auth_token works.

import os
from anthropic import Anthropic

client = Anthropic(
    # Global region; China region is https://cn.inf.space (accelerated) or https://global.inf.space (international)
    base_url="https://ai.inf.space",
    api_key=os.environ["INFERENCE_SPACE_API_KEY"],  # gateway Key starting with gk_
)

msg = client.messages.create(
    model="claude-sonnet-4-6",  # replace with a model enabled for your Key
    max_tokens=1024,
    messages=[{"role": "user", "content": "Introduce yourself in three sentences."}],
)
print(msg.content[0].text)
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  // Global region; China region is https://cn.inf.space (accelerated) or https://global.inf.space (international)
  baseURL: "https://ai.inf.space",
  apiKey: process.env.INFERENCE_SPACE_API_KEY, // gateway Key starting with gk_
});

const msg = await client.messages.create({
  model: "claude-sonnet-4-6", // replace with a model enabled for your Key
  max_tokens: 1024,
  messages: [{ role: "user", content: "Introduce yourself in three sentences." }],
});
console.log(msg.content[0].text);

Other tools

Any tool that accepts a custom OpenAI or Anthropic endpoint (LangChain, LiteLLM, Vercel AI SDK, Cherry Studio, and others) works with the Base URL from the table above and a gk_ Key. Common problems:

  • 401: wrong Key; the tool picked up another Key from an environment variable (such as OPENAI_API_KEY or ANTHROPIC_API_KEY); or the Key's region does not match the host.
  • 404: /v1 added or missing in the Base URL. The OpenAI protocol needs /v1; the Anthropic protocol does not.
  • Model unavailable: check that model is within the Key's allowed models.

For parameters, streaming, and error handling, see Chat Completions, Messages, Responses, and Error codes and handling.

On this page