Wild West API

Change the OpenAI base URL in any client

Every OpenAI client sends requests to a base URL and appends the path itself. By default that is https://api.openai.com/v1. Change it, and the same code talks to any OpenAI-compatible endpoint instead.

The default, and what replaces it

The default base URL is https://api.openai.com/v1. An OpenAI-compatible provider gives you its own; for Wild West API it is https://wildwestapi.com/v1. The base ends at /v1: the client adds /chat/completions, /responses or /models after it.

With an environment variable

The official Python and Node SDKs read OPENAI_BASE_URL and OPENAI_API_KEY when no value is passed in code, so many tools built on them can be redirected without a code change.

export OPENAI_BASE_URL="https://wildwestapi.com/v1"
export OPENAI_API_KEY="sk-ww-..."

Python SDK

from openai import OpenAI

client = OpenAI(base_url="https://wildwestapi.com/v1", api_key="sk-ww-...")

Node and TypeScript SDK

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://wildwestapi.com/v1", apiKey: "sk-ww-..." });

Note the capitalisation: base_url in Python, baseURL in JavaScript.

LangChain

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="outlaw-1-xploded", base_url="https://wildwestapi.com/v1", api_key="sk-ww-...")

Full setup: LangChain guide.

LlamaIndex

from llama_index.llms.openai_like import OpenAILike

llm = OpenAILike(model="outlaw-1-xploded", api_base="https://wildwestapi.com/v1", api_key="sk-ww-...", is_chat_model=True)

OpenAILike rather than OpenAI, because the plain class checks the model name against OpenAI's own list. Full setup: LlamaIndex guide.

Vercel AI SDK

Full setup: Vercel AI SDK guide.

LiteLLM

from litellm import completion

resp = completion(
    model="openai/outlaw-1-xploded",
    api_base="https://wildwestapi.com/v1",
    api_key="sk-ww-...",
    messages=[{"role": "user", "content": "Hello"}],
)

The openai/ prefix tells LiteLLM to use the OpenAI format against the base you give it. Full setup: LiteLLM guide.

Errors that mean the base URL is wrong

  • 404 on every call: the path is doubled (a base ending in /chat/completions) or /v1 is missing.
  • 401 from the new host: the base URL changed but the key is still the old provider's.
  • 401 from api.openai.com: the base URL did not take, and the request went to OpenAI. Check for a setting that overrides the environment variable.
  • 404 naming the model: the base URL is right but the model id is not one the new host serves. Copy it from https://wildwestapi.com/v1/models.

Coding tools set the base URL in their own settings; the guides show where for each one, and OpenAI-compatible API covers what the endpoint has to support.

FAQ

What is the OpenAI API base URL?

https://api.openai.com/v1 by default. A compatible provider replaces it with its own, such as https://wildwestapi.com/v1.

What environment variable sets the OpenAI base URL?

OPENAI_BASE_URL, read by the official Python and Node SDKs when no base URL is passed in code. Some older tools use OPENAI_API_BASE instead.

Should the base URL include /chat/completions?

No. The SDK appends the path. Only a field that explicitly asks for the full endpoint takes https://wildwestapi.com/v1/chat/completions.

Related

Uncensored AI models on one key

OpenAI and Anthropic compatible, pay as you go. New to it? Start with uncensored AI, explained.