Skip to navigationSkip to main contentSkip to footerScaleway DocsAsk our AI
Ask our AI

Generative APIs - Quickstart

Scaleway Generative APIs provide programmatic access to AI models for generating new content, such as text and code.

By using our pre-configured, serverless endpoints of leading AI models, you eliminate the need to configure hardware or deploy your own models.

Hosted in European data centers and priced competitively per million tokens used, Generative APIs enable efficient and scalable integration of AI capabilities into your applications.

Before you start

To complete the actions presented below, you must have:

  • A Scaleway account logged into the console
  • Owner status or IAM permissions allowing you to perform actions in the intended Organization
  • A valid API key
  • Python 3.7+ installed on your system

Interacting with Generative APIs via the playground

The Scaleway console provides a web playground for chat-based models hosted on Generative APIs. This allows you to interact with these models via a visual interface, sending your prompt and getting an immediate text-based response.

How to access the playground

  1. Navigate to Generative APIs under the AI section of the Scaleway console side menu. The list of available models displays.

  2. Click the name of the chat model you want to try. Alternatively, click more icon next to the chat model, and click Try model in the menu.

The web playground displays.

How to use the playground

  1. Choose a model from the drop-down list at the top of the page.

  2. Enter a prompt at the bottom of the page, for example Tell me a joke.

    Tip

    You can also click one of the suggested prompts in the conversation area, such as Translate text, Rewrite email or Code a pong game, to instantly send a pre-prepared prompt and get the model's response.

  3. Edit the hyperparameters listed on the right column, for example the default temperature for more or less randomness on the model's output.

  4. Click the send button to send your prompt and view the model's response in the conversation area, for example Why don’t scientists trust atoms anymore? Because they make up everything!

    Tip

    You can click View code next to the model dropdown to get code snippets you can integrate directly into your Python, Javascript and cURL code bases when querying a model programatically. These snippets are configured according to the settings you have entered in the playground.

Interacting with Generative APIs programatically

This example shows you how to start using Generative APIs in your Python code, via the OpenAI Python SDK.

How to install the OpenAI Python SDK

Tip

Ensure Python is installed on your local machine. If you need to install Python, download it from python.org.

Run the following command:

pip install openai

How to configure and set your API key and service URL

  1. Have your Scaleway API key ready, or generate a new one from the Scaleway console.

  2. Add the following code to your Python script:

    from openai import OpenAI
    
    client = OpenAI(
        base_url="https://api.scaleway.ai/v1", # # Scaleway's Generative APIs service URL
        api_key="<SCW_SECRET_KEY>" # Your unique API secret key from Scaleway
    )

    Make sure that you replace <SCW_SECRET_KEY> with the API key obtained from your Scaleway account.

    Tip

    We recommend storing your API keys securely using environment variables or secret management tools to prevent unauthorized access.

How to send your first API request

After installing OpenAI and adding setting up the client with the base URL and API key, you are now ready to make your first API request.

Below is an example for generating a description of a futuristic city.

  1. Ensure your code already contains the openai import statement and creation of a configured OpenAI client as shown above.

  2. Create a chat completion for Llama 3.1 8b instruct by adding the following to your code:

    completion = client.chat.completions.create(
      model="llama-3.1-8b-instruct",
      messages=[{"role": "user", "content": "Describe a futuristic city with advanced technology and green energy solutions."}],
      temperature=0.7,
      max_tokens=100
    )
  3. Output the result by adding the following to your code:

    print(completion.choices[0].message.content)
    Tip

    The whole code snippet should look like this:

    from openai import OpenAI
    
    client = OpenAI(
        base_url="https://api.scaleway.ai/v1", # # Scaleway's Generative APIs service URL
        api_key="<SCW_SECRET_KEY>" # Your unique API secret key from Scaleway
    )
    
    # Create chat completion
    completion = client.chat.completions.create(
      model="llama-3.1-8b-instruct",
      messages=[{"role": "user", "content": "Describe a futuristic city with advanced technology and green energy solutions."}],
      temperature=0.7,
      max_tokens=100
    
    # Output model's response
    print(completion.choices[0].message.content)
    )

This very simple example demonstrates how the Chat API can be used to generate creative content based on your prompts.

Going further

Now that you are familiar with the basics, explore the full potential of Generative APIs by customizing your API requests. Refer to our How-to guides for more advanced features and usage.

Still need help?

Create a support ticket
No Results