Skip to main content
You can work with Nebius Token Factory by using Portkey. The integration is based on the AI Gateway by Portkey. The AI Gateway allows users to send requests to different AI providers and still use the same Portkey interface. The solution assumes that you send requests to the AI Gateway, and then it routes and sends them to Nebius Token Factory. As a result, you interact with Nebius Token Factory models via Portkey. The integration is based on the OpenAI Node.js package and the Nebius Token Factory provider for Portkey. To use the integration, do the following:
  1. Create a Nebius API key for authentication.
  2. Create a Portkey API key for authentication.
  3. Save the keys to the environment variables:
    export NEBIUS_API_KEY=<Nebius_API_key>
    export PORTKEY_API_KEY=<Portkey_API_key>
    
  4. Configure the integration:
    1. Install the Portkey SDK:
      npm i --save portkey-ai
      
    2. Create the following portkey.js script:
      import OpenAI from 'openai'; // v4 SDK
      import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai'
      
      const openai = new OpenAI({
        apiKey: process.env["NEBIUS_API_KEY"],
        baseURL: PORTKEY_GATEWAY_URL,
        defaultHeaders: createHeaders({
          provider: "nebius",
          apiKey: process.env["PORTKEY_API_KEY"]
        })
      });
      
      async function main() {
        const chatCompletion = await openai.chat.completions.create({
          messages: [{ role: 'user', content: 'Say this is a test' }],
          model: 'deepseek-ai/DeepSeek-R1-fast',
        });
      
        console.log(chatCompletion.choices);
      }
      
      main();
      
      This script sends a multi-message request to the specified model in Nebius Token Factory.
    3. Run the script:
      node portkey.js
      
      The output is the following:
      [
        {
          finish_reason: 'stop',
          index: 0,
          logprobs: null,
          message: {
            content: 'This is a test. How can I assist you further?',
            refusal: null,
            role: 'assistant',
            audio: null,
            function_call: null,
            tool_calls: []
          },
          stop_reason: null
        }
      ]