Skip to content

hazelcaffe/paip-openai-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PAIP-OpenAI-API

An OpenAI-compatible API backed by the Palantir AIP LLM Proxy.

Setup

git clone https://github.com/hazelcaffe/paip-openai-api
cd paip-openai-api
bun install
cp .env.example .env

Configure .env:

PALANTIR_AIP_URL=https://example.palantirfoundry.com
PALANTIR_AIP_API_TOKEN=your-foundry-token

# Optional. When set, clients must send Authorization: Bearer <API_KEY>.
API_KEY=

HOST=0.0.0.0
PORT=3000

Start the server:

bun run start

For development with automatic reload:

bun run dev

OpenAPI documentation is available at http://localhost:3000/docs.

How Authentication Works

Palantir credentials are server credentials. Configure them once on the API server with PALANTIR_AIP_URL and PALANTIR_AIP_API_TOKEN; clients must not receive or submit those credentials.

API_KEY is an optional credential for this gateway:

  • When API_KEY is set, clients send Authorization: Bearer <API_KEY>.
  • When API_KEY is unset, /v1/* is unauthenticated.

The gateway replaces the client authorization header with the Foundry token before contacting Palantir.

OpenAI SDK

Use a model ID from GET /v1/models (e.g. gpt-5.5, claude-opus-4.8, etc.)

import OpenAI from "openai";

const client = new OpenAI({
    apiKey: process.env.PAIP_OPENAI_API_KEY,
    baseURL: "http://localhost:3000/v1"
});

const completion = await client.chat.completions.create({
    model: "claude-opus-4.8",
    messages: [
        {
            role: "user",
            content: "Explain zero data retention in one paragraph."
        }
    ]
});

console.log(completion.choices[0]?.message.content);

The Responses API is also supported:

const response = await client.responses.create({
    model: "gemini-3.1-pro",
    input: "Write a concise release note."
});

console.log(response.output_text);

HTTP Endpoints

Method Path Description
GET /v1/models Lists models
POST /v1/chat/completions OpenAI Chat Completions-compatible API
POST /v1/responses OpenAI Responses-compatible API
POST /v1/embeddings Foundry OpenAI embeddings
GET /health Health check
GET /docs OpenAPI documentation

Example:

curl http://localhost:3000/v1/chat/completions \
    -H "Authorization: Bearer $PAIP_OPENAI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
        "model": "gpt-5.5",
        "messages": [
            {
                "role": "user",
                "content": "Hello"
            }
        ]
    }'

Provider Behavior

  • OpenAI models use Foundry's OpenAI endpoints directly, preserving native request fields, response fields, tool calls, and token streaming.
  • Anthropic models are translated to the Anthropic Messages endpoint.
  • Gemini models are translated to the Google generateContent endpoint.
  • OpenAI-style function tools, system messages, text, and common image inputs are adapted for Anthropic and Gemini.
  • For adapted providers, stream: true returns valid SSE framing after the provider response completes. It is not token-by-token streaming.
  • attribution, traceparent, and tracestate request headers are forwarded to Foundry.

The supplied model catalog contains generation models but no embedding model. For /v1/embeddings, pass the embedding model RID from Foundry Model Catalog as the model value.

Models

Requests accept:

  • The public model ID, such as gpt-5.5, claude-opus-4.8, or gemini-3.1-pro
  • The full Foundry model RID

The current catalog includes models like GPT 5.5, Claude Opus 4.8, Gemini 3.1 Pro, and more. For a full list, check src/models.ts.

xAI and other models listed in the Model Catalog are not available as they cannot be queried from the LLM proxy.

Development

bun run typecheck
# Requires .env to be properly configured
bun test

License

MIT

Releases

No releases published

Packages

 
 
 

Contributors