Quick Start Guide
Learn how to make your first API request to MX4 Atlas using the standard OpenAI SDK.
MX4 Atlas is designed to be a drop-in replacement for OpenAI. This means you can use the libraries and tools you already know, just by changing the configuration.
Get your API Key
You'll need an API key to authenticate your requests. If you don't have one yet, contact sales to request access to the Private Beta.
Note: Your API key (`mx4-sk-...`) carries full privileges for your account. Keep it secure and never commit it to public repositories.
Install the OpenAI SDK
Since MX4 Atlas is API-compatible with OpenAI, you don't need a special "MX4" library. Just install the standard OpenAI Python package.
1pip install openai
Configure the Client
Initialize the client by pointing it to the MX4 Atlas API endpoint.
1import openai2import os34client = openai.OpenAI(5 # Set the base URL to MX4 Atlas6 base_url="https://api.mx4.ai/v1",7 # Use your MX4 API Key8 api_key="mx4-sk-1234567890abcdef"9)
Make your first request
Now you can call the Chat Completions API just like you're used to. We recommend starting with the `mx4-atlas-core` model for the best balance of Arabic reasoning and performance.
1response = client.chat.completions.create(2 model="mx4-atlas-core",3 messages=[4 {"role": "system", "content": "You are a helpful assistant."},5 {"role": "user", "content": "Hello, who are you?"}6 ]7)89print(response.choices[0].message.content)
You should see a response identifying the model as MX4 Atlas, running on sovereign infrastructure.
Other Languages & Methods
JavaScript/Node.js
1const OpenAI = require('openai');23const client = new OpenAI({4 apiKey: process.env.MX4_API_KEY,5 baseURL: 'https://api.mx4.ai/v1'6});78async function main() {9 const message = await client.chat.completions.create({10 model: 'mx4-atlas-core',11 messages: [{ role: 'user', content: 'Hello' }]12 });13 console.log(message.choices[0].message.content);14}1516main();
cURL
1curl https://api.mx4.ai/v1/chat/completions \2 -H "Content-Type: application/json" \3 -H "Authorization: Bearer $MX4_API_KEY" \4 -d '{5 "model": "mx4-atlas-core",6 "messages": [7 {"role": "user", "content": "Hello"}8 ]9 }'
Error Handling
Always handle errors gracefully in production. Here's a best-practice example:
1import openai2from openai import APIError, AuthenticationError, RateLimitError34client = openai.OpenAI(5 api_key="mx4-sk-...",6 base_url="https://api.mx4.ai/v1"7)89try:10 response = client.chat.completions.create(11 model="mx4-atlas-core",12 messages=[{"role": "user", "content": "Hello"}],13 timeout=3014 )15 print(response.choices[0].message.content)1617except AuthenticationError:18 print("Invalid API key. Check your credentials.")19except RateLimitError:20 print("Rate limit exceeded. Wait before retrying.")21except APIError as e:22 print(f"API error: {e.status_code} {e.message}")
Common Issues & Solutions
❌ ModuleNotFoundError: No module named 'openai'
Run pip install --upgrade openai (requires version 1.0+)
❌ 401 Unauthorized
Your API key is missing or incorrect. Check that it starts with mx4-sk-
❌ Model not found
Your account may not have access to that model. Check the Model Garden for available models in your region.