Documentation▾

Migrate from OpenAI to Porten

For an application that uses Chat Completions, migration starts with two settings: a Porten API key and https://porten.ai/v1 as the base URL. You also need to choose a model ID from Porten's catalog. A GPT model name does not automatically map to an equivalent Porten model, and the same API format does not imply the same response quality.

1. Create a key and choose a model

Create a key in API keys. Use a separate server-side secret for Porten; do not send your OpenAI key to another provider or put the key in browser code.

export PORTEN_API_KEY="sk-porten-…"
curl --fail-with-body https://porten.ai/v1/models \
  -H "Authorization: Bearer $PORTEN_API_KEY"

Choose a chat model from the response and set PORTEN_MODEL to its exact id in your server environment. Check its capabilities, context window and current availability in the model catalog. A listed model ID does not guarantee spare capacity for your key's region and node class. See models and loading.

2. Update the client configuration

With OpenAI's Python SDK, the rest of a simple Chat Completions request can keep the same structure:

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["PORTEN_API_KEY"],
    base_url="https://porten.ai/v1",
)
response = client.chat.completions.create(
    model=os.environ["PORTEN_MODEL"],
    messages=[{"role": "user", "content": "Write a short greeting."}],
    max_tokens=128,
)
print(response.choices[0].message.content)

For streaming, use stream=True and read chunk.choices[0].delta.content when choices is not empty. Complete Python and TypeScript examples are in the Quickstart; settings for existing tools are in the integration guide.

3. Define the migration scope

Existing feature Check before switching
Text chat and streaming Test Chat Completions with your chosen model and handle empty stream chunks.
Tool calls, JSON or image input Check the model's verified capabilities and test representative inputs.
Embeddings Check the model and dimensions; rebuild the vector index if the embedding model changes.
Responses, Assistants or provider-stored conversations Changing the base URL is not enough. Porten's documented chat interface is /v1/chat/completions; the application must manage conversation history.
Billing and limits Porten has its own balance, pricing, quotas and model selection.

Use the API reference to determine which endpoints and parameters are supported. Do not migrate an entire application solely because a simple chat request works.

4. Validate before switching production traffic

Run the same representative requests against both implementations. Compare answer correctness, tool arguments, context limits, latency and actual cost in Activity. Also test an unavailable model, an interrupted stream and limited capacity. Bound your retries: a connection can fail after inference has already started.

Keep a configurable rollback path during rollout. If region or node ownership is a requirement, automatic fallback routing must enforce the same requirement. Read the data residency comparison before choosing a policy.

The SDK configuration is supported by OpenAI's official Python SDK. The example uses Chat Completions; verify compatibility with the SDK version and features your application uses.

📄 Reading as a machine? This page is available as raw Markdown at https://porten.ai/docs/migrate-from-openai.md — or grab the whole site via llms.txt / llms-full.txt.