NavigationContentFooter
Jump toSuggest an edit

Generative APIs - Quickstart

Reviewed on 30 October 2024Published on 04 September 2024

Generative APIs offer seamless access to pre-configured, serverless endpoints of leading AI models. No need to configure hardware or deploy your own models.

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

Important

This service is free while in beta. Specific terms and conditions apply.

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

Start with the Generative APIs Playground

Scaleway provides a web playground for instruct-based models hosted on Generative APIs.

Accessing the Playground

  1. Navigate to Generative APIs under the AI section of the Scaleway console side menu. The list of models you can query displays.
  2. Click the name of the chat model you want to try. Alternatively, click «See more Icon» next to the chat model, and click Try model in the menu.

The web playground displays.

Using the playground

  1. Enter a prompt at the bottom of the page, or use one of the suggested prompts in the conversation area.
  2. Edit the hyperparameters listed on the right column, for example the default temperature for more or less randomness on the outputs.
  3. Switch models at the top of the page, to observe the capabilities of chat models offered via Generative APIs.
  4. Click View code to get code snippets configured according to your settings in the playground.

Install the OpenAI Python SDK

To start using Generative APIs in your code, you can install the OpenAI Python SDK. Run the following command:

pip install openai
Tip

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

Configure and set your API key and service URL

  1. Have your API key ready or generate a new one from the Scaleway console.
  2. Use the following code in 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

It is recommended to store your API keys securely using environment variables or secret management tools to prevent unauthorized access.

Send your first API request

You are now ready to make your first API request. Below is an example of generating a description of a futuristic city:

from openai import OpenAI
# Initialize the client with your base URL and API key
client = OpenAI(
base_url="https://api.scaleway.ai/v1",
api_key="<SCW_API_KEY>"
)
# Create a chat completion for Llama 3.1 8b instruct
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 the result
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.

API DocsScaleway consoleDedibox consoleScaleway LearningScaleway.comPricingBlogCareers
© 2023-2024 – Scaleway