SDK · Integration
Connect the OpenAI SDK to Tikway: Python and Node.js configuration
Last updated:
If your application uses the OpenAI SDK, configure the Tikway base URL, key and catalog model ID in the existing client. This guide covers Chat Completions text requests. After changing the URL, check parameters and responses; it does not establish compatibility for Responses, tools or image endpoints.
1. Prepare your model and key
Choose a text model supporting OpenAI Chat Completions in the catalog and copy its complete ID. Create your Tikway key in the console. Use https://api.tikway.ai/v1 as the SDK base URL; the SDK appends /chat/completions to form /v1/chat/completions.
Do not use the complete operation path as the base URL or substitute a key from an OpenAI account. The commands below use Bash on macOS, Linux or WSL. In PowerShell, set current-session variables with $env:TIKWAY_API_KEY='YOUR_KEY' and $env:TIKWAY_MODEL='CATALOG_MODEL_ID'.
export TIKWAY_API_KEY='YOUR_TIKWAY_API_KEY'
export TIKWAY_MODEL='FULL_MODEL_ID_FROM_CATALOG'
2. Python example
Install openai in your application’s virtual environment:
python -m pip install openai
Save as sdk_chat.py. Running it sends a real request under applicable billing rules. The key is read only from the environment.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["TIKWAY_API_KEY"],
base_url="https://api.tikway.ai/v1",
timeout=60.0,
max_retries=0,
)
response = client.chat.completions.create(
model=os.environ["TIKWAY_MODEL"],
messages=[{"role": "user", "content": "Reply only with OK"}],
)
print(response.choices[0].message.content)
print(response.usage)
python sdk_chat.py
3. Node.js example
Install the SDK in your Node.js project and save the ESM example as sdk_chat.mjs:
npm install openai
import OpenAI from 'openai'
if (!process.env.TIKWAY_API_KEY || !process.env.TIKWAY_MODEL) {
throw new Error('Set TIKWAY_API_KEY and TIKWAY_MODEL first')
}
const client = new OpenAI({
apiKey: process.env.TIKWAY_API_KEY,
baseURL: 'https://api.tikway.ai/v1',
timeout: 60000,
maxRetries: 0
})
const response = await client.chat.completions.create({
model: process.env.TIKWAY_MODEL,
messages: [{ role: 'user', content: 'Reply only with OK' }]
})
console.log(response.choices[0].message.content)
console.log(response.usage)
node sdk_chat.mjs
Automatic retries are disabled here to make first-request troubleshooting clearer. Production applications should use bounded retries appropriate to the error; a client timeout does not prove no server work occurred.
4. Verify the configuration change
Check the actual request hostname, explicit client URL and model ID, then find the request at the same timestamp in Tikway’s records. Model, protocol, tokens and charges help reconcile that request. One successful answer does not verify every client feature.
For streaming, read the Node.js SSE guide. For tools, separately test definitions, returned arguments and tool-result messages. For Responses, confirm the model’s supported endpoint first.
5. Common questions
Why does the changed URL still return 401? Check the key actually used and whether the SDK instance reads stale configuration. See 401 troubleshooting.
Can I copy another provider’s model name? Copy Tikway’s complete catalog ID. Display names, official IDs and gateway IDs can differ; do not change prefixes yourself.
Can I avoid an SDK? The Python standard-library guide needs no third-party Python package.
How do I estimate cost? Use the free cost calculator, then reconcile actual usage and request records.