UnderSky Docs

Migrate an OpenAI integration

Move an existing OpenAI SDK or HTTP integration to UnderSky by changing the base URL, API key, model ID, and operational checks.

UnderSky accepts the OpenAI request shape for chat completions, Responses, embeddings, and image generation. Most integrations need four changes.

Change the client settings

Set the base URL to https://api.undersky.ai/v1 and load an UnderSky key from your secret manager.

import os

from openai import OpenAI

client = OpenAI(
    api_key=os.environ["UNDERSKY_API_KEY"],
    base_url="https://api.undersky.ai/v1",
)

Keep the API key on the server. Do not expose it in browser code.

Choose a supported model

Start with auto while validating the integration. For predictable routing, choose a model from the UnderSky model directory and pin that ID in your configuration.

response = client.chat.completions.create(
    model="gpt-6-luna",
    messages=[{"role": "user", "content": "Hello"}],
)

Do not copy an OpenAI model ID unless it appears in the current public model list.

Preserve streaming and tools

The stream, tools, tool_choice, and response_format fields use the OpenAI-compatible chat endpoint. Keep your existing event parser and tool execution loop, then run a request against the chat reference.

Update error handling

Add handling for UnderSky-specific credit and gateway states:

  • 402 means that the account needs more credits.
  • 429 requires bounded exponential backoff.
  • 5xx can be retried for idempotent requests after checking status.
  • 401 means that the key is invalid or unavailable to the process.

Use the error code guide and rate-limit guide to set retry limits.

Validate before production

  1. Call GET /v1/models without authentication and confirm that your selected model is listed.
  2. Send one non-streaming request with a small prompt.
  3. Send one streaming request and verify that your parser stops at [DONE].
  4. Confirm usage appears in Dashboard → Settings → Credit & Usage.
  5. Check pricing and service status before setting production budgets.

The Quick Start includes curl, Python, Node, image, JSON, and recovery examples.

On this page