Skip to content

Code examples

These examples call NexoAI through its OpenAI-compatible API using the public base https://api.nexoai.ma. Each one reads the key from the environment and sends a small chat-completions request.

Avant de lancer

Set the OpenAI-compatible variable pair in the current shell:

bash
export OPENAI_BASE_URL="https://api.nexoai.ma"
export OPENAI_API_KEY="sk-your-key"
powershell
$env:OPENAI_BASE_URL = "https://api.nexoai.ma"
$env:OPENAI_API_KEY = "sk-your-key"

Then choose the example that matches your stack:

  • curl proves the endpoint, key, and model without SDK behavior in the middle.
  • Python uses the official openai package with a custom base.
  • Node.js and TypeScript use the openai npm package with type-safe access.

All examples use gpt-5.4. Replace only the model string to try another current ID such as claude-opus-4-8, gemini-3-pro-preview, grok-4.5, deepseek-v4-flash, or qwen3-coder-next.

Base URL rule

The environment variable contains the gateway root:

text
https://api.nexoai.ma

The examples append /v1 when constructing the SDK base or append /v1/chat/completions for the raw HTTP request. This keeps one canonical environment value and prevents accidental /v1/v1 paths.

Server-side only

Do not ship OPENAI_API_KEY in browser JavaScript or a public mobile bundle. Call NexoAI from your server, edge function, or another trusted runtime.

Built for developers across MENA.