# OpenAI SDK Use the official OpenAI Python or JavaScript client. Set base_url and api_key. Point any official OpenAI client at PrivateMind by setting its `base_url` and `api_key`. The rest of your code stays the same. ## Python ```python from openai import OpenAI client = OpenAI( base_url="https://api.privatemind.com/v1", api_key="PMIND...:abcdef...", ) resp = client.chat.completions.create( model="", messages=[{"role": "user", "content": "Hello"}], ) print(resp.choices[0].message.content) ``` ## TypeScript / Node.js ```typescript import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://api.privatemind.com/v1", apiKey: "PMIND...:abcdef...", }); const resp = await client.chat.completions.create({ model: "", messages: [{ role: "user", content: "Hello" }], }); console.log(resp.choices[0].message.content); ``` ## Responses API The same clients call the [Responses API](https://docs.privatemind.com/responses-api.html) through `client.responses`. PrivateMind stores no responses, so leave out `previous_response_id` and send the whole conversation in `input`. ```python from openai import OpenAI client = OpenAI( base_url="https://api.privatemind.com/v1", api_key="PMIND...:abcdef...", ) resp = client.responses.create( model="", input="Hello", ) print(resp.output_text) ``` Streaming from Node.js: ```typescript import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://api.privatemind.com/v1", apiKey: "PMIND...:abcdef...", }); const stream = client.responses.stream({ model: "", input: "Write a haiku about TCP.", }); for await (const event of stream) { if (event.type === "response.output_text.delta") process.stdout.write(event.delta); } ``` In Python, `client.responses.parse` with a pydantic model works too: see [Structured output](https://docs.privatemind.com/responses-api.html#structured-output). ## OpenAI Agents SDK The [OpenAI Agents SDK](https://openai.github.io/openai-agents-python/) runs on the Responses API. Give it a client pointed at PrivateMind through `OpenAIResponsesModel`: ```python from agents import Agent, OpenAIResponsesModel, Runner, function_tool, set_tracing_disabled from openai import AsyncOpenAI client = AsyncOpenAI( base_url="https://api.privatemind.com/v1", api_key="PMIND...:abcdef...", ) set_tracing_disabled(True) @function_tool def get_weather(city: str) -> str: """Get current weather for a city.""" return "18C, overcast" agent = Agent( name="Assistant", instructions="You are a concise assistant.", model=OpenAIResponsesModel(model="", openai_client=client), tools=[get_weather], ) result = Runner.run_sync(agent, "What is the weather in Paris?") print(result.final_output) ``` Tools and `output_type` work together: if the agent's final output doesn't match `output_type`, it is generated again with the format enforced (see [With tools on offer](https://docs.privatemind.com/responses-api.html#with-tools-on-offer)). By default the SDK sends a trace of every run, model inputs and outputs included, to OpenAI whenever it has a key to send it with. It uses `OPENAI_API_KEY`, or a key or client you passed to `set_default_openai_key` or `set_default_openai_client`. If you pass your PrivateMind key or client to either function, the SDK sends that key to OpenAI too. Keep `set_tracing_disabled(True)`. ## Go ```go import ( "context" "fmt" openai "github.com/openai/openai-go" "github.com/openai/openai-go/option" ) client := openai.NewClient( option.WithBaseURL("https://api.privatemind.com/v1"), option.WithAPIKey("PMIND...:abcdef..."), ) resp, _ := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{ Model: openai.F(""), Messages: openai.F([]openai.ChatCompletionMessageParamUnion{ openai.UserMessage("Hello"), }), }) fmt.Println(resp.Choices[0].Message.Content) ``` ## LangChain ```python from langchain_openai import ChatOpenAI llm = ChatOpenAI( base_url="https://api.privatemind.com/v1", api_key="PMIND...:abcdef...", model="", ) print(llm.invoke("Hello").content) ``` ## LlamaIndex ```python from llama_index.llms.openai_like import OpenAILike llm = OpenAILike( api_base="https://api.privatemind.com/v1", api_key="PMIND...:abcdef...", model="", is_chat_model=True, ) ``` Use `OpenAILike` because PrivateMind speaks the OpenAI wire format from a host other than api.openai.com. ## What works, what doesn't Anything that calls `/v1/chat/completions`, `/v1/responses`, `/v1/embeddings`, `/v1/models`, `/v1/images/generations` or `/v1/audio/*` works. The [Files](https://docs.privatemind.com/files.html) and [Batch](https://docs.privatemind.com/batch.html) APIs are there too, so `client.files.*` and `client.batches.*` work unchanged. SDK features that call endpoints PrivateMind doesn't have, such as the Assistants API and fine-tuning, return `404`. To fine-tune a model on your org's GPUs, use [`pm.finetune`](https://docs.privatemind.com/sdk-finetune.html) in the PrivateMind SDK. It takes OpenAI's chat and preference file formats. Training jobs, image generation and batch work also have a native SDK: the [PrivateMind Python SDK](https://docs.privatemind.com/sdk.html). Code written for the Anthropic SDKs works too, through the [Messages API](https://docs.privatemind.com/messages-api.html): see [Anthropic SDK](https://docs.privatemind.com/anthropic-sdk.html). ## Where next - [Quickstart](https://docs.privatemind.com/quickstart.html) for the shortest path to a first request. - [Chat completions](https://docs.privatemind.com/chat-completions.html) for the full parameter list the SDKs forward. - [Responses API](https://docs.privatemind.com/responses-api.html) for what `client.responses` supports. - [Models](https://docs.privatemind.com/models.html) to feature-detect what's live in your org.