NavigationContentFooter
Jump toSuggest an edit

Generative APIs - Quickstart

Reviewed on 04 September 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:

  • Access to this service is restricted while in beta. You can request access to the product by filling out a form on the Scaleway’s betas page.
  • 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’s Playground is in development, stay tuned!

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",
api_key="<SCW_API_KEY>"
)

Make sure that you replace <SCW_API_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.

Docs APIScaleway consoleDedibox consoleScaleway LearningScaleway.comPricingBlogCarreer
© 2023-2024 – Scaleway